]> andersk Git - libfaim.git/blame - utils/faimtest/faimtest.c
- Tue Jun 6 01:36:48 UTC 2000
[libfaim.git] / utils / faimtest / faimtest.c
CommitLineData
9de3ca7e 1/*
2 * -----------------------------------------------------------
3 * ProtoFAIM: v1.xx.xxplxx
4 * -----------------------------------------------------------
5 *
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.
9 * Work is continuing.
10 *
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.
14 *
15 * Its very ugly. Probably always will be. Nothing is more
16 * ugly than the backend itself, however.
17 *
18 * -----------------------------------------------------------
19 *
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.
24 *
25 * Most everything:
26 * (c) 1998 Adam Fritzler, PST, afritz@iname.com
27 *
28 * The password algorithms
29 * (c) 1998 Brock Wilcox, awwaiid@iname.com
30 *
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.
36 *
37 * -----------------------------------------------------------
38 *
39 */
40
41/*
42 Current status:
43
44
45 */
46
397055b1 47#include <faim/aim.h>
48
49int faimtest_parse_oncoming(struct aim_session_t *, struct command_rx_struct *, ...);
50int faimtest_parse_offgoing(struct aim_session_t *, struct command_rx_struct *, ...);
51int faimtest_parse_login_phase3d_f(struct aim_session_t *, struct command_rx_struct *, ...);
01b59e1e 52int faimtest_parse_authresp(struct aim_session_t *, struct command_rx_struct *, ...);
397055b1 53int faimtest_parse_incoming_im(struct aim_session_t *, struct command_rx_struct *command, ...);
54int faimtest_parse_userinfo(struct aim_session_t *, struct command_rx_struct *command, ...);
55int faimtest_handleredirect(struct aim_session_t *, struct command_rx_struct *command, ...);
56int faimtest_authsvrready(struct aim_session_t *, struct command_rx_struct *command, ...);
57int faimtest_pwdchngdone(struct aim_session_t *, struct command_rx_struct *command, ...);
58int faimtest_serverready(struct aim_session_t *, struct command_rx_struct *command, ...);
59int faimtest_parse_misses(struct aim_session_t *, struct command_rx_struct *command, ...);
01b59e1e 60int faimtest_parse_motd(struct aim_session_t *, struct command_rx_struct *command, ...);
61int faimtest_parse_login(struct aim_session_t *, struct command_rx_struct *command, ...);
0c20631f 62int faimtest_chatnav_info(struct aim_session_t *, struct command_rx_struct *command, ...);
63int faimtest_chat_incomingmsg(struct aim_session_t *sess, struct command_rx_struct *command, ...);
64int faimtest_chat_infoupdate(struct aim_session_t *sess, struct command_rx_struct *command, ...);
65int faimtest_chat_leave(struct aim_session_t *sess, struct command_rx_struct *command, ...);
66int faimtest_chat_join(struct aim_session_t *sess, struct command_rx_struct *command, ...);
5e02cf44 67int faimtest_parse_connerr(struct aim_session_t *sess, struct command_rx_struct *command, ...);
49c8a2fa 68
f1a5efe0 69static char *screenname,*password,*server=NULL;
26af6789 70
9de3ca7e 71int main(void)
72{
397055b1 73 struct aim_session_t aimsess;
f1a5efe0 74 struct aim_conn_t *authconn = NULL, *waitingconn = NULL;
b8d0da45 75 int keepgoing = 1, stayconnected = 1;
5e02cf44 76
77#if 0
78 /* Use something like this for AIM */
01b59e1e 79 struct client_info_s info = {"FAIMtest (Hi guys!)", 3, 5, 1670, "us", "en"};
5e02cf44 80#else
81 /* or something exactly like this for ICQ and AIM */
82 struct client_info_s info = {"Random String (libfaim)", 4, 30, 3141, "us", "en"};
83#endif
b8d0da45 84 int selstat = 0;
85
397055b1 86 aim_session_init(&aimsess);
9de3ca7e 87
26af6789 88 if ( !(screenname = getenv("SCREENNAME")) ||
89 !(password = getenv("PASSWORD")))
90 {
91 printf("Must specify SCREENAME and PASSWORD in environment.\n");
92 return -1;
93 }
94
f1a5efe0 95 server = getenv("AUTHSERVER");
96
397055b1 97 /*
98 * (I used a goto-based loop here because n wanted quick proof
99 * that reconnecting without restarting was actually possible...)
100 */
9de3ca7e 101 enter:
f1a5efe0 102 authconn = aim_newconn(&aimsess, AIM_CONN_TYPE_AUTH, server?server:FAIM_LOGIN_SERVER);
397055b1 103
040457cc 104 if (authconn == NULL) {
105 fprintf(stderr, "faimtest: internal connection error while in aim_login. bailing out.\n");
106 return -1;
107 } else if (authconn->fd == -1) {
108 if (authconn->status & AIM_CONN_STATUS_RESOLVERR)
109 fprintf(stderr, "faimtest: could not resolve authorizer name\n");
110 else if (authconn->status & AIM_CONN_STATUS_CONNERR)
111 fprintf(stderr, "faimtest: could not connect to authorizer\n");
112 aim_conn_kill(&aimsess, &authconn);
113 return -1;
114 } else {
01b59e1e 115#ifdef SNACLOGIN
040457cc 116 /* new login code -- not default -- pending new password encryption algo */
117 aim_conn_addhandler(&aimsess, authconn, 0x0017, 0x0007, faimtest_parse_login, 0);
118 aim_conn_addhandler(&aimsess, authconn, 0x0017, 0x0003, faimtest_parse_authresp, 0);
119
120 aim_sendconnack(&aimsess, authconn);
121 aim_request_login(&aimsess, authconn, FAIMTEST_SCREENNAME);
01b59e1e 122#else
040457cc 123 aim_conn_addhandler(&aimsess, authconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_AUTHSUCCESS, faimtest_parse_authresp, 0);
124 aim_conn_addhandler(&aimsess, authconn, AIM_CB_FAM_GEN, AIM_CB_GEN_SERVERREADY, faimtest_authsvrready, 0);
125 aim_send_login(&aimsess, authconn, screenname, password, &info);
01b59e1e 126#endif
040457cc 127 }
9de3ca7e 128
b8d0da45 129 while (keepgoing) {
f1a5efe0 130 waitingconn = aim_select(&aimsess, NULL, &selstat);
b8d0da45 131
132 switch(selstat) {
133 case -1: /* error */
134 keepgoing = 0;
135 break;
9de3ca7e 136
b8d0da45 137 case 0: /* no events pending */
138 break;
139
140 case 1: /* outgoing data pending */
141 aim_tx_flushqueue(&aimsess);
142 break;
143
144 case 2: /* incoming data pending */
f1a5efe0 145 if (aim_get_command(&aimsess, waitingconn) < 0) {
9de3ca7e 146 printf("\afaimtest: connection error!\n");
b8d0da45 147 } else
397055b1 148 aim_rxdispatch(&aimsess);
b8d0da45 149 break;
150
151 default:
152 break; /* invalid */
9de3ca7e 153 }
b8d0da45 154 }
9de3ca7e 155
156 /* Close up */
b8d0da45 157 printf("AIM just decided we didn't need to be here anymore, closing up...\n");
9de3ca7e 158
159 /* close up all connections, dead or no */
397055b1 160 aim_logoff(&aimsess);
9de3ca7e 161
b8d0da45 162 if (stayconnected) {
9de3ca7e 163 printf("\nTrying to reconnect in 2 seconds...\n");
164 sleep(2);
165 goto enter;
166 }
167
168 /* Get out */
169 exit(0);
170}
171
397055b1 172int faimtest_serverready(struct aim_session_t *sess, struct command_rx_struct *command, ...)
9de3ca7e 173{
174 switch (command->conn->type)
175 {
176 case AIM_CONN_TYPE_BOS:
26af6789 177
397055b1 178 aim_bos_reqrate(sess, command->conn); /* request rate info */
179 aim_bos_ackrateresp(sess, command->conn); /* ack rate info response -- can we say timing? */
180 aim_bos_setprivacyflags(sess, command->conn, 0x00000003);
9de3ca7e 181
182#if 0
397055b1 183 aim_bos_reqpersonalinfo(sess, command->conn);
9de3ca7e 184#endif
185
397055b1 186 /* Request advertisement service -- see comment in handleredirect */
187 aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_ADS);
01b59e1e 188 aim_setversions(sess, command->conn);
9de3ca7e 189
190#if 0
397055b1 191 aim_bos_reqrights(sess, command->conn);
192 aim_bos_reqbuddyrights(sess, command->conn);
193 aim_bos_reqlocaterights(sess, command->conn);
194 aim_bos_reqicbmparaminfo(sess, command->conn);
9de3ca7e 195#endif
196
197 /* set group permissions */
397055b1 198 aim_bos_setgroupperm(sess, command->conn, 0x1f);
9de3ca7e 199 fprintf(stderr, "faimtest: done with BOS ServerReady\n");
200 break;
0c20631f 201
9de3ca7e 202 case AIM_CONN_TYPE_CHATNAV:
203 fprintf(stderr, "faimtest: chatnav: got server ready\n");
0c20631f 204 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CTN, AIM_CB_CTN_INFO, faimtest_chatnav_info, 0);
205 aim_bos_reqrate(sess, command->conn);
206 aim_bos_ackrateresp(sess, command->conn);
207 aim_chatnav_clientready(sess, command->conn);
208 aim_chatnav_reqrights(sess, command->conn);
209
210 break;
211 case AIM_CONN_TYPE_CHAT:
212 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN, faimtest_chat_join, 0);
213 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE, faimtest_chat_leave, 0);
214 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE, faimtest_chat_infoupdate, 0);
215 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_INCOMINGMSG, faimtest_chat_incomingmsg, 0);
216 aim_bos_reqrate(sess, command->conn);
217 aim_bos_ackrateresp(sess, command->conn);
218 aim_chat_clientready(sess, command->conn);
9de3ca7e 219 break;
220 default:
221 fprintf(stderr, "faimtest: unknown connection type on Server Ready\n");
222 }
223 return 1;
224}
225
226/*
227 handleredirect()...
228
229 This, of course, handles Service Redirects from OSCAR.
230
231 Should get passed in the following:
232 struct command_rx_struct *command
233 the raw command data
234 int serviceid
235 the destination service ID
236 char *serverip
237 the IP address of the service's server
238 char *cookie
239 the raw auth cookie
240 */
397055b1 241int faimtest_handleredirect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
9de3ca7e 242{
243 va_list ap;
244 int serviceid;
245 char *ip;
246 char *cookie;
247
248 /* this is the new buddy list */
0c20631f 249 char buddies[] = "Buddy1&Buddy2&ThisHereIsAName2&";
9de3ca7e 250 /* this is the new profile */
251 char profile[] = "Hello";
252
253 va_start(ap, command);
254 serviceid = va_arg(ap, int);
255 ip = va_arg(ap, char *);
256 cookie = va_arg(ap, char *);
0c20631f 257
9de3ca7e 258 switch(serviceid)
259 {
260 case 0x0005: /* Advertisements */
261 /*
262 * The craziest explanation yet as to why we finish logging in when
263 * we get the advertisements redirect, of which we don't use anyway....
264 * IT WAS EASY!
265 */
266
267 /* send the buddy list and profile (required, even if empty) */
397055b1 268 aim_bos_setbuddylist(sess, command->conn, buddies);
5b79dc93 269 aim_bos_setprofile(sess, command->conn, profile, NULL, AIM_CAPS_CHAT);
9de3ca7e 270
271 /* send final login command (required) */
397055b1 272 aim_bos_clientready(sess, command->conn); /* tell BOS we're ready to go live */
9de3ca7e 273
274 /* you should now be ready to go */
397055b1 275 printf("\nYou are now officially online.\n");
9de3ca7e 276
277 break;
278 case 0x0007: /* Authorizer */
279 {
280 struct aim_conn_t *tstconn;
281 /* Open a connection to the Auth */
397055b1 282 tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, ip);
9de3ca7e 283 if ( (tstconn==NULL) || (tstconn->status >= AIM_CONN_STATUS_RESOLVERR) )
284 fprintf(stderr, "faimtest: unable to reconnect with authorizer\n");
285 else
286 /* Send the cookie to the Auth */
397055b1 287 aim_auth_sendcookie(sess, tstconn, cookie);
9de3ca7e 288
289 }
290 break;
291 case 0x000d: /* ChatNav */
292 {
293 struct aim_conn_t *tstconn = NULL;
397055b1 294 tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHATNAV, ip);
040457cc 295 if ( (tstconn==NULL) || (tstconn->status >= AIM_CONN_STATUS_RESOLVERR)) {
296 fprintf(stderr, "faimtest: unable to connect to chatnav server\n");
297 if (tstconn) aim_conn_kill(sess, &tstconn);
298 return 1;
299 }
0c20631f 300#if 0
397055b1 301 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_CTN, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
302 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_GEN, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
0c20631f 303#endif
304 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, faimtest_serverready, 0);
397055b1 305 aim_auth_sendcookie(sess, tstconn, cookie);
9de3ca7e 306 fprintf(stderr, "\achatnav: connected\n");
307 }
308 break;
309 case 0x000e: /* Chat */
310 {
0c20631f 311 char *roomname = NULL;
9de3ca7e 312 struct aim_conn_t *tstconn = NULL;
0c20631f 313
314 roomname = va_arg(ap, char *);
315
397055b1 316 tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHAT, ip);
9de3ca7e 317 if ( (tstconn==NULL) || (tstconn->status >= AIM_CONN_STATUS_RESOLVERR))
318 {
319 fprintf(stderr, "faimtest: unable to connect to chat server\n");
040457cc 320 if (tstconn) aim_conn_kill(sess, &tstconn);
9de3ca7e 321 return 1;
0c20631f 322 }
323 printf("faimtest: chat: connected\n");
324
325 /*
326 * We must do this to attach the stored name to the connection!
327 */
328 aim_chat_attachname(tstconn, roomname);
329
330 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, faimtest_serverready, 0);
331 aim_auth_sendcookie(sess, tstconn, cookie);
9de3ca7e 332 }
333 break;
334 default:
335 printf("uh oh... got redirect for unknown service 0x%04x!!\n", serviceid);
336 /* dunno */
337 }
338
9de3ca7e 339 va_end(ap);
340
0c20631f 341 return 1;
9de3ca7e 342}
343
01b59e1e 344int faimtest_parse_authresp(struct aim_session_t *sess, struct command_rx_struct *command, ...)
9de3ca7e 345{
9de3ca7e 346 struct aim_conn_t *bosconn = NULL;
9de3ca7e 347
01b59e1e 348
397055b1 349 printf("Screen name: %s\n", sess->logininfo.screen_name);
01b59e1e 350
351 /*
352 * Check for error.
353 */
354 if (sess->logininfo.errorcode)
355 {
356 printf("Login Error Code 0x%04x\n", sess->logininfo.errorcode);
357 printf("Error URL: %s\n", sess->logininfo.errorurl);
040457cc 358 aim_conn_kill(sess, &command->conn);
01b59e1e 359 exit(0); /* XXX: should return in order to let the above things get free()'d. */
360 }
361
397055b1 362 printf("Reg status: %2d\n", sess->logininfo.regstatus);
363 printf("Email: %s\n", sess->logininfo.email);
397055b1 364 printf("BOS IP: %s\n", sess->logininfo.BOSIP);
9de3ca7e 365
366 printf("Closing auth connection...\n");
040457cc 367 aim_conn_kill(sess, &command->conn);
397055b1 368 bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, sess->logininfo.BOSIP);
040457cc 369 if (bosconn == NULL) {
370 fprintf(stderr, "faimtest: could not connect to BOS: internal error\n");
371 } else if (bosconn->status != 0) {
372 fprintf(stderr, "faimtest: could not connect to BOS\n");
373 aim_conn_kill(sess, &bosconn);
374 } else {
375 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ACK, AIM_CB_ACK_ACK, NULL, 0);
376 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_SERVERREADY, faimtest_serverready, 0);
377 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATEINFO, NULL, 0);
378 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_REDIRECT, faimtest_handleredirect, 0);
379 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_STS, AIM_CB_STS_SETREPORTINTERVAL, NULL, 0);
380 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING, faimtest_parse_oncoming, 0);
381 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING, faimtest_parse_offgoing, 0);
382 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_INCOMING, faimtest_parse_incoming_im, 0);
383 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_ERROR, faimtest_parse_misses, 0);
384 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_MISSEDCALL, faimtest_parse_misses, 0);
385 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATECHANGE, faimtest_parse_misses, 0);
386 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ERROR, faimtest_parse_misses, 0);
387 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO, faimtest_parse_userinfo, 0);
388
389 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_CTN, AIM_CB_CTN_DEFAULT, aim_parse_unknown, 0);
390 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
391 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, faimtest_parse_motd, 0);
392
393 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR, faimtest_parse_connerr, 0);
394
395 aim_auth_sendcookie(sess, bosconn, sess->logininfo.cookie);
396 }
9de3ca7e 397 return 1;
398}
399
397055b1 400int faimtest_parse_userinfo(struct aim_session_t *sess, struct command_rx_struct *command, ...)
9de3ca7e 401{
402 struct aim_userinfo_s *userinfo;
403 char *prof_encoding = NULL;
404 char *prof = NULL;
5e02cf44 405 unsigned short inforeq = 0;
9de3ca7e 406
407 va_list ap;
408 va_start(ap, command);
409 userinfo = va_arg(ap, struct aim_userinfo_s *);
410 prof_encoding = va_arg(ap, char *);
411 prof = va_arg(ap, char *);
5e02cf44 412 inforeq = va_arg(ap, unsigned short);
9de3ca7e 413 va_end(ap);
414
415 printf("faimtest: userinfo: sn: %s\n", userinfo->sn);
416 printf("faimtest: userinfo: warnlevel: 0x%04x\n", userinfo->warnlevel);
417 printf("faimtest: userinfo: class: 0x%04x = ", userinfo->class);
418
419 /*
420 * 00000000 (binary)
421 * 1 Trial
422 * 2 Unknown
423 * 3 AOL
424 * 4 Unknown
425 * 5 Free
426 *
427 * ORed together.
428 *
429 */
430
431 if (userinfo->class & 0x0001)
432 printf("TRIAL ");
433 if (userinfo->class & 0x0002)
434 printf("UNKNOWN_BIT2 ");
435 if (userinfo->class & 0x0004)
436 printf("AOL ");
437 if (userinfo->class & 0x0008)
438 printf("UNKNOWN_BIT4 ");
439 if (userinfo->class & 0x0010)
440 printf("FREE ");
040457cc 441 if (userinfo->class & 0x0040)
442 printf("ICQ? ");
9de3ca7e 443 printf("\n");
444
445 printf("faimtest: userinfo: membersince: %lu\n", userinfo->membersince);
446 printf("faimtest: userinfo: onlinesince: %lu\n", userinfo->onlinesince);
447 printf("faimtest: userinfo: idletime: 0x%04x\n", userinfo->idletime);
448
5e02cf44 449 if (inforeq == AIM_GETINFO_GENERALINFO) {
450 printf("faimtest: userinfo: profile_encoding: %s\n", prof_encoding ? prof_encoding : "[none]");
451 printf("faimtest: userinfo: prof: %s\n", prof ? prof : "[none]");
452 } else if (inforeq == AIM_GETINFO_AWAYMESSAGE) {
453 printf("faimtest: userinfo: awaymsg_encoding: %s\n", prof_encoding ? prof_encoding : "[none]");
454 printf("faimtest: userinfo: awaymsg: %s\n", prof ? prof : "[none]");
455 } else
456 printf("faimtest: userinfo: unknown info request\n");
9de3ca7e 457
458 return 1;
459}
460
461/*
462 * The user-level Incoming ICBM callback.
463 *
464 * Arguments:
465 * struct command_rx_struct * command if you feel like doing it yourself
466 * char * srcsn the source name
467 * char * msg message
468 * int warnlevel warning/evil level
469 * int class user class
470 * ulong membersince time_t of date of signup
471 * ulong onsince time_t of date of singon
472 * int idletime min (sec?) idle
24286d93 473 * u_int icbmflags sets AIM_IMFLAGS_{AWAY,ACK}
9de3ca7e 474 *
475 */
397055b1 476int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_struct *command, ...)
9de3ca7e 477{
26af6789 478 int channel;
9de3ca7e 479 va_list ap;
9de3ca7e 480
481 va_start(ap, command);
26af6789 482 channel = va_arg(ap, int);
9de3ca7e 483
26af6789 484 /*
485 * Channel 1: Standard Message
486 */
040457cc 487 if (channel == 1) {
488 struct aim_userinfo_s *userinfo;
489 char *msg = NULL;
490 u_int icbmflags = 0;
491 char *tmpstr = NULL;
492 u_short flag1, flag2;
493
494 userinfo = va_arg(ap, struct aim_userinfo_s *);
495 msg = va_arg(ap, char *);
496 icbmflags = va_arg(ap, u_int);
497 flag1 = va_arg(ap, u_short);
498 flag2 = va_arg(ap, u_short);
499 va_end(ap);
500
501 printf("faimtest: icbm: sn = \"%s\"\n", userinfo->sn);
502 printf("faimtest: icbm: warnlevel = 0x%04x\n", userinfo->warnlevel);
503 printf("faimtest: icbm: class = 0x%04x ", userinfo->class);
504 if (userinfo->class & 0x0010)
505 printf("(FREE) ");
506 if (userinfo->class & 0x0001)
507 printf("(TRIAL) ");
508 if (userinfo->class & 0x0004)
509 printf("(AOL) ");
510 printf("\n");
511 printf("faimtest: icbm: membersince = %lu\n", userinfo->membersince);
512 printf("faimtest: icbm: onlinesince = %lu\n", userinfo->onlinesince);
513 printf("faimtest: icbm: idletime = 0x%04x\n", userinfo->idletime);
514
515 printf("faimtest: icbm: icbmflags = ");
516 if (icbmflags & AIM_IMFLAGS_AWAY)
517 printf("away ");
518 if (icbmflags & AIM_IMFLAGS_ACK)
519 printf("ackrequest ");
520 printf("\n");
521
522 printf("faimtest: icbm: encoding flags = {%04x, %04x}\n", flag1, flag2);
523
524 printf("faimtest: icbm: message: %s\n", msg);
525
526 if (msg) {
527 tmpstr = index(msg, '>');
528 if (tmpstr != NULL)
529 tmpstr+=1;
530 else
531 tmpstr = msg;
532
533 if ( (strlen(tmpstr) >= 10) &&
534 (!strncmp(tmpstr, "disconnect", 10)) ) {
535 aim_send_im(sess, command->conn, "midendian", 0, "ta ta...");
536 aim_logoff(sess);
537 } else if (strstr(tmpstr, "goodday")) {
538 printf("faimtest: icbm: sending response\n");
539 aim_send_im(sess, command->conn, userinfo->sn, 0, "Good day to you too.");
540 } else if (!strncmp(tmpstr, "open chatnav", 12)) {
541 aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_CHATNAV);
542 //aim_chat_join(sess, command->conn, "thishereisaname2_chat85");
543 } else if (!strncmp(tmpstr, "create", 6)) {
544 aim_chatnav_createroom(sess, aim_getconn_type(sess, AIM_CONN_TYPE_CHATNAV), "WorldDomination", 0x0004);
545 } else if (!strncmp(tmpstr, "close chatnav", 13)) {
546 struct aim_conn_t *chatnavconn;
547 chatnavconn = aim_getconn_type(sess, AIM_CONN_TYPE_CHATNAV);
548 aim_conn_kill(sess, &chatnavconn);
549 } else if (!strncmp(tmpstr, "join", 4)) {
550 aim_chat_join(sess, command->conn, 0x0004, "worlddomination");
551 } else if (!strncmp(tmpstr, "leave", 5))
552 aim_chat_leaveroom(sess, "worlddomination");
553 else if (!strncmp(tmpstr, "getinfo", 7)) {
554 aim_getinfo(sess, command->conn, "75784102", AIM_GETINFO_GENERALINFO);
555 aim_getinfo(sess, command->conn, "15853637", AIM_GETINFO_AWAYMESSAGE);
556 } else {
557 printf("unknown command.\n");
558 }
559
560 }
561 }
562 /*
563 * Channel 2: Rendevous Request
564 */
565 else if (channel == 2) {
566 struct aim_userinfo_s *userinfo;
567 unsigned short reqclass;
568
569 reqclass = va_arg(ap, unsigned short);
570 switch (reqclass) {
571 case AIM_RENDEZVOUS_VOICE: {
26af6789 572 userinfo = va_arg(ap, struct aim_userinfo_s *);
26af6789 573 va_end(ap);
9de3ca7e 574
040457cc 575 printf("faimtest: voice invitation: source sn = %s\n", userinfo->sn);
576 printf("faimtest: voice invitation: \twarnlevel = 0x%04x\n", userinfo->warnlevel);
577 printf("faimtest: voice invitation: \tclass = 0x%04x ", userinfo->class);
26af6789 578 if (userinfo->class & 0x0010)
579 printf("(FREE) ");
580 if (userinfo->class & 0x0001)
581 printf("(TRIAL) ");
582 if (userinfo->class & 0x0004)
583 printf("(AOL) ");
584 printf("\n");
040457cc 585 /* we dont get membersince on chat invites! */
586 printf("faimtest: voice invitation: \tonlinesince = %lu\n", userinfo->onlinesince);
587 printf("faimtest: voice invitation: \tidletime = 0x%04x\n", userinfo->idletime);
26af6789 588
040457cc 589 break;
590 }
591 case AIM_RENDEZVOUS_FILETRANSFER: {
592 printf("faimtset: file transfer!\n");
593 break;
594 }
595 case AIM_RENDEZVOUS_CHAT_EX3:
596 case AIM_RENDEZVOUS_CHAT_EX4:
597 case AIM_RENDEZVOUS_CHAT_EX5: {
598 char *msg,*encoding,*lang;
599 struct aim_chat_roominfo *roominfo;
26af6789 600
040457cc 601 userinfo = va_arg(ap, struct aim_userinfo_s *);
602 roominfo = va_arg(ap, struct aim_chat_roominfo *);
603 msg = va_arg(ap, char *);
604 encoding = va_arg(ap, char *);
605 lang = va_arg(ap, char *);
606 va_end(ap);
26af6789 607
040457cc 608 printf("faimtest: chat invitation: source sn = %s\n", userinfo->sn);
609 printf("faimtest: chat invitation: \twarnlevel = 0x%04x\n", userinfo->warnlevel);
610 printf("faimtest: chat invitation: \tclass = 0x%04x ", userinfo->class);
611 if (userinfo->class & 0x0010)
612 printf("(FREE) ");
613 if (userinfo->class & 0x0001)
614 printf("(TRIAL) ");
615 if (userinfo->class & 0x0004)
616 printf("(AOL) ");
617 printf("\n");
618 /* we dont get membersince on chat invites! */
619 printf("faimtest: chat invitation: \tonlinesince = %lu\n", userinfo->onlinesince);
620 printf("faimtest: chat invitation: \tidletime = 0x%04x\n", userinfo->idletime);
26af6789 621
040457cc 622 printf("faimtest: chat invitation: message = %s\n", msg);
623 printf("faimtest: chat invitation: room name = %s\n", roominfo->name);
624 printf("faimtest: chat invitation: encoding = %s\n", encoding);
625 printf("faimtest: chat invitation: language = %s\n", lang);
626 printf("faimtest: chat invitation: exchange = 0x%04x\n", roominfo->exchange);
627 printf("faimtest: chat invitation: instance = 0x%04x\n", roominfo->instance);
628 printf("faimtest: chat invitiation: autojoining %s...\n", roominfo->name);
629 /*
630 * Automatically join room...
631 */
632 aim_chat_join(sess, command->conn, 0x0004, roominfo->name);
633 break;
634 }
635 default:
636 printf("faimtest: icbm: unknown reqclass (%d)\n", reqclass);
637 } /* switch */
638 } else
26af6789 639 printf("faimtest does not support channels > 2 (chan = %02x)\n", channel);
9de3ca7e 640 printf("faimtest: icbm: done with ICBM handling\n");
641
642 return 1;
643}
644
397055b1 645int faimtest_authsvrready(struct aim_session_t *sess, struct command_rx_struct *command, ...)
9de3ca7e 646{
647 printf("faimtest_authsvrready: called (contype: %d)\n", command->conn->type);
648 sleep(10);
649 /* should just be able to tell it we're ready too... */
397055b1 650 aim_auth_clientready(sess, command->conn);
9de3ca7e 651
652#if 0
653 /*
654 * This is where you'd really begin changing your password.
655 * However, this callback may get called for reasons other
656 * than you wanting to change your password. You should
657 * probably check that before actually doing it.
658 */
397055b1 659 aim_auth_changepasswd(sess, command->conn, "PWD1", "PWD2");
9de3ca7e 660#endif
661
662 return 1;
663}
664
397055b1 665int faimtest_pwdchngdone(struct aim_session_t *sess, struct command_rx_struct *command, ...)
9de3ca7e 666{
667 printf("PASSWORD CHANGE SUCCESSFUL!!!\n");
668 return 1;
669}
670
397055b1 671int faimtest_parse_oncoming(struct aim_session_t *sess, struct command_rx_struct *command, ...)
9de3ca7e 672{
673 struct aim_userinfo_s *userinfo;
674
675 va_list ap;
676 va_start(ap, command);
677 userinfo = va_arg(ap, struct aim_userinfo_s *);
678 va_end(ap);
679
0c20631f 680 printf("\n%s is now online (class: %04x = %s%s%s%s%s%s%s%s)\n", userinfo->sn, userinfo->class,
681 (userinfo->class&AIM_CLASS_TRIAL)?" TRIAL":"",
682 (userinfo->class&AIM_CLASS_UNKNOWN2)?" UNKNOWN2":"",
683 (userinfo->class&AIM_CLASS_AOL)?" AOL":"",
684 (userinfo->class&AIM_CLASS_UNKNOWN4)?" UNKNOWN4":"",
685 (userinfo->class&AIM_CLASS_FREE)?" FREE":"",
686 (userinfo->class&AIM_CLASS_AWAY)?" AWAY":"",
687 (userinfo->class&AIM_CLASS_UNKNOWN40)?" UNKNOWN40":"",
688 (userinfo->class&AIM_CLASS_UNKNOWN80)?" UNKNOWN80":"");
9de3ca7e 689
690 return 1;
691}
692
397055b1 693int faimtest_parse_offgoing(struct aim_session_t *sess, struct command_rx_struct *command, ...)
9de3ca7e 694{
397055b1 695 char *sn;
696 va_list ap;
697
698 va_start(ap, command);
699 sn = va_arg(ap, char *);
700 va_end(ap);
9de3ca7e 701
397055b1 702 printf("\n%s has left\n", sn);
9de3ca7e 703
704 return 1;
705}
706
01b59e1e 707int faimtest_parse_motd(struct aim_session_t *sess, struct command_rx_struct *command, ...)
708{
709 char *msg;
710 u_short id;
711 va_list ap;
712
713 va_start(ap, command);
714 id = va_arg(ap, u_short);
715 msg = va_arg(ap, char *);
716 va_end(ap);
717
718 printf("faimtest: motd: %s\n", msg);
719
720 return 1;
721}
9de3ca7e 722
723/*
724 * Handles callbacks for: AIM_CB_RATECHANGE, AIM_CB_USERERROR,
725 * AIM_CB_MISSED_IM, and AIM_CB_MISSED_CALL.
726 */
397055b1 727int faimtest_parse_misses(struct aim_session_t *sess, struct command_rx_struct *command, ...)
9de3ca7e 728{
729 u_short family;
730 u_short subtype;
731
397055b1 732 family = aimutil_get16(command->data+0);
733 subtype= aimutil_get16(command->data+2);
9de3ca7e 734
735 switch (family)
736 {
737 case 0x0001:
738 if (subtype == 0x000a) /* or AIM_CB_RATECHANGE */
739 printf("\n****STOP SENDING/RECIEVING MESSAGES SO FAST!****\n\n");
740 break;
741 case 0x0002:
742 if (subtype == 0x0001) /* or AIM_CB_USERERROR */
743 {
744 u_long snacid = 0x00000000;
745
746 snacid = aimutil_get32(&command->data[6]);
747
748 printf("Received unknown error in SNAC family 0x0002 (snacid = %08lx)\n", snacid);
749 }
750 break;
751 case 0x0004:
752 if (subtype == 0x0001) /* or AIM_CB_MISSED_IM */
753 printf("\n***LAST IM DIDN\'T MAKE IT BECAUSE THE BUDDY IS NOT ONLINE***\n\n");
754 else if (subtype == 0x000a) /* or AIM_CB_MISSED_CALL */
755 printf("You missed some messages from %s because they were sent too fast\n", &(command->data[13]));
756 break;
757 }
758
759 return 0;
760}
761
01b59e1e 762#ifdef SNACLOGIN
763int faimtest_parse_login(struct aim_session_t *sess, struct command_rx_struct *command, ...)
764{
765 struct client_info_s info = {"FAIMtest (Hi guys!)", 3, 5, 1670, "us", "en"};
766 u_char authcookie[11];
767 int i;
768
769 for (i = 0; i < (int)command->data[11]; i++)
770 authcookie[i] = command->data[12+i];
771 authcookie[i] = '\0';
9de3ca7e 772
01b59e1e 773 printf("faimtest: logincookie: %s\n", authcookie);
774
775 aim_send_login(sess, command->conn, FAIMTEST_SCREENNAME, FAIMTEST_PASSWORD, &info);
776
777 return 1;
778}
779#endif
0c20631f 780
781int faimtest_chat_join(struct aim_session_t *sess, struct command_rx_struct *command, ...)
782{
783 va_list ap;
784 struct aim_userinfo_s *userinfo;
785 int count = 0, i = 0;
786
787 va_start(ap, command);
788 count = va_arg(ap, int);
789 userinfo = va_arg(ap, struct aim_userinfo_s *);
790 va_end(ap);
791
792 printf("faimtest: chat: %s: New occupants have joined:\n", (char *)command->conn->priv);
793 while (i < count)
794 printf("faimtest: chat: %s: \t%s\n", (char *)command->conn->priv, userinfo[i++].sn);
795
796 return 1;
797}
798
799int faimtest_chat_leave(struct aim_session_t *sess, struct command_rx_struct *command, ...)
800{
801 va_list ap;
802 struct aim_userinfo_s *userinfo;
803 int count = 0, i = 0;
804
805 va_start(ap, command);
806 count = va_arg(ap, int);
807 userinfo = va_arg(ap, struct aim_userinfo_s *);
808 va_end(ap);
809
810 printf("faimtest: chat: %s: Some occupants have left:\n", (char *)command->conn->priv);
811 while (i < count)
812 printf("faimtest: chat: %s: \t%s\n", (char *)command->conn->priv, userinfo[i++].sn);
813
814 return 1;
815}
816
817int faimtest_chat_infoupdate(struct aim_session_t *sess, struct command_rx_struct *command, ...)
818{
819 va_list ap;
820 struct aim_userinfo_s *userinfo;
821 struct aim_chat_roominfo *roominfo;
822 char *roomname;
823 int usercount,i;
824 char *roomdesc;
aa6efcfd 825 unsigned short unknown_c9, unknown_d2, unknown_d5, maxmsglen;
826 unsigned long creationtime;
0c20631f 827
828 va_start(ap, command);
829 roominfo = va_arg(ap, struct aim_chat_roominfo *);
830 roomname = va_arg(ap, char *);
831 usercount= va_arg(ap, int);
832 userinfo = va_arg(ap, struct aim_userinfo_s *);
833 roomdesc = va_arg(ap, char *);
aa6efcfd 834 unknown_c9 = va_arg(ap, unsigned short);
835 creationtime = va_arg(ap, unsigned long);
836 maxmsglen = va_arg(ap, unsigned short);
837 unknown_d2 = va_arg(ap, unsigned short);
838 unknown_d5 = va_arg(ap, unsigned short);
0c20631f 839 va_end(ap);
840
841 printf("faimtest: chat: %s: info update:\n", (char *)command->conn->priv);
842 printf("faimtest: chat: %s: \tRoominfo: {%04x, %s, %04x}\n",
843 (char *)command->conn->priv,
844 roominfo->exchange,
845 roominfo->name,
846 roominfo->instance);
847 printf("faimtest: chat: %s: \tRoomname: %s\n", (char *)command->conn->priv, roomname);
848 printf("faimtest: chat: %s: \tRoomdesc: %s\n", (char *)command->conn->priv, roomdesc);
849 printf("faimtest: chat: %s: \tOccupants: (%d)\n", (char *)command->conn->priv, usercount);
850
851 i = 0;
852 while (i < usercount)
853 printf("faimtest: chat: %s: \t\t%s\n", (char *)command->conn->priv, userinfo[i++].sn);
854
aa6efcfd 855 printf("faimtest: chat: %s: \tUnknown_c9: 0x%04x\n", (char *)command->conn->priv, unknown_c9);
856 printf("faimtest: chat: %s: \tCreation time: %lu (time_t)\n", (char *)command->conn->priv, creationtime);
857 printf("faimtest: chat: %s: \tMax message length: %d bytes\n", (char *)command->conn->priv, maxmsglen);
858 printf("faimtest: chat: %s: \tUnknown_d2: 0x%04x\n", (char *)command->conn->priv, unknown_d2);
859 printf("faimtest: chat: %s: \tUnknown_d5: 0x%02x\n", (char *)command->conn->priv, unknown_d5);
860
0c20631f 861 return 1;
862}
863
864int faimtest_chat_incomingmsg(struct aim_session_t *sess, struct command_rx_struct *command, ...)
865{
866 va_list ap;
867 struct aim_userinfo_s *userinfo;
868 char *msg;
869 char tmpbuf[1152];
870
871 va_start(ap, command);
872 userinfo = va_arg(ap, struct aim_userinfo_s *);
873 msg = va_arg(ap, char *);
874 va_end(ap);
875
876 printf("faimtest: chat: %s: incoming msg from %s: %s\n", (char *)command->conn->priv, userinfo->sn, msg);
877
878 /*
879 * Do an echo for testing purposes. But not for ourselves ("oops!")
880 */
881 if (strcmp(userinfo->sn, sess->logininfo.screen_name) != 0)
882 {
883 sprintf(tmpbuf, "(%s said \"%s\")", userinfo->sn, msg);
884 aim_chat_send_im(sess, command->conn, tmpbuf);
885 }
886
887 return 1;
888}
889
890int faimtest_chatnav_info(struct aim_session_t *sess, struct command_rx_struct *command, ...)
891{
892 u_short type;
893 va_list ap;
894
895 ap = va_start(ap, command);
896 type = va_arg(ap, u_short);
897
898 switch(type)
899 {
900 case 0x0002:
901 {
902 int maxrooms;
903 struct aim_chat_exchangeinfo *exchanges;
904 int exchangecount,i = 0;
905
906 maxrooms = va_arg(ap, u_char);
907 exchangecount = va_arg(ap, int);
908 exchanges = va_arg(ap, struct aim_chat_exchangeinfo *);
909 va_end(ap);
910
911 printf("faimtest: chat info: Chat Rights:\n");
912 printf("faimtest: chat info: \tMax Concurrent Rooms: %d\n", maxrooms);
913
914 printf("faimtest: chat info: \tExchange List: (%d total)\n", exchangecount);
915 while (i < exchangecount)
916 {
917 printf("faimtest: chat info: \t\t%x: %s (%s/%s)\n",
918 exchanges[i].number,
919 exchanges[i].name,
920 exchanges[i].charset1,
921 exchanges[i].lang1);
922 i++;
923 }
924
925 }
926 break;
927 default:
928 va_end(ap);
929 printf("faimtest: chatnav info: unknown type (%04x)\n", type);
930 }
931 return 1;
932}
5e02cf44 933
934int faimtest_parse_connerr(struct aim_session_t *sess, struct command_rx_struct *command, ...)
935{
936 va_list ap;
937 unsigned short code;
938 char *msg = NULL;
939
940 ap = va_start(ap, command);
941 code = va_arg(ap, unsigned short);
942 msg = va_arg(ap, char *);
943 va_end(ap);
944
945 printf("faimtest: connerr: Code 0x%04x: %s\n", code, msg);
946
947 return 1;
948}
This page took 3.624848 seconds and 5 git commands to generate.