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