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