From: mid Date: Wed, 13 Dec 2000 02:29:37 +0000 (+0000) Subject: - Wed Dec 13 02:26:39 UTC 2000 X-Git-Tag: rel_0_99_2~85 X-Git-Url: http://andersk.mit.edu/gitweb/libfaim.git/commitdiff_plain/1ea867e3531824627556aaf5bf7d23fdf33325fb - Wed Dec 13 02:26:39 UTC 2000 - Create aim_cachesnac() - Some long overdue cleanups --- diff --git a/CHANGES b/CHANGES index 5ee16cd..61a3704 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,10 @@ No release numbers ------------------ + - Wed Dec 13 02:26:39 UTC 2000 + - Create aim_cachesnac() + - Some long overdue cleanups + - Wed Dec 13 00:38:56 UTC 2000 - Added the client update/version info to the authresp callback - Added the prototype for aim_getfile_send_chunk to aim.h diff --git a/aim_auth.c b/aim_auth.c index 1fb9cfa..d110451 100644 --- a/aim_auth.c +++ b/aim_auth.c @@ -52,20 +52,9 @@ faim_export unsigned long aim_auth_clientready(struct aim_session_t *sess, aim_tx_enqueue(sess, newpacket); - { - struct aim_snac_t snac; - - snac.id = sess->snac_nextid; - snac.family = 0x0001; - snac.type = 0x0004; - snac.flags = 0x0000; + aim_cachesnac(sess, 0x0001, 0x0004, 0x0000, NULL, 0); - snac.data = NULL; - - aim_newsnac(sess, &snac); - } - - return (sess->snac_nextid++); + return sess->snac_nextid; } faim_export unsigned long aim_auth_changepasswd(struct aim_session_t *sess, @@ -90,18 +79,7 @@ faim_export unsigned long aim_auth_changepasswd(struct aim_session_t *sess, aim_tx_enqueue(sess, newpacket); - { - struct aim_snac_t snac; - - snac.id = sess->snac_nextid; - snac.family = 0x0001; - snac.type = 0x0004; - snac.flags = 0x0000; - - snac.data = NULL; - - aim_newsnac(sess, &snac); - } + aim_cachesnac(sess, 0x0001, 0x0004, 0x0000, NULL, 0); - return (sess->snac_nextid++); + return sess->snac_nextid; } diff --git a/aim_buddylist.c b/aim_buddylist.c index 26165bc..a9b9ef8 100644 --- a/aim_buddylist.c +++ b/aim_buddylist.c @@ -28,23 +28,9 @@ faim_export unsigned long aim_add_buddy(struct aim_session_t *sess, aim_tx_enqueue(sess, newpacket ); -#if 0 /* do we really need this code? */ - { - struct aim_snac_t snac; - - snac.id = sess->snac_nextid; - snac.family = 0x0003; - snac.type = 0x0004; - snac.flags = 0x0000; - - snac.data = malloc( strlen( sn ) + 1 ); - memcpy( snac.data, sn, strlen( sn ) + 1 ); - - aim_newsnac(sess, &snac); - } -#endif - - return( sess->snac_nextid++ ); + aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1); + + return sess->snac_nextid; } faim_export unsigned long aim_remove_buddy(struct aim_session_t *sess, @@ -69,21 +55,9 @@ faim_export unsigned long aim_remove_buddy(struct aim_session_t *sess, aim_tx_enqueue(sess, newpacket); - { - struct aim_snac_t snac; - - snac.id = sess->snac_nextid; - snac.family = 0x0003; - snac.type = 0x0005; - snac.flags = 0x0000; - - snac.data = malloc( strlen( sn ) + 1 ); - memcpy( snac.data, sn, strlen( sn ) + 1 ); - - aim_newsnac(sess, &snac ); - } + aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1); - return( sess->snac_nextid++ ); + return sess->snac_nextid; } faim_internal int aim_parse_buddyrights(struct aim_session_t *sess, @@ -92,7 +66,6 @@ faim_internal int aim_parse_buddyrights(struct aim_session_t *sess, rxcallback_t userfunc = NULL; int ret=1; struct aim_tlvlist_t *tlvlist; - struct aim_tlv_t *tlv; unsigned short maxbuddies = 0, maxwatchers = 0; /* @@ -104,9 +77,8 @@ faim_internal int aim_parse_buddyrights(struct aim_session_t *sess, /* * TLV type 0x0001: Maximum number of buddies. */ - if ((tlv = aim_gettlv(tlvlist, 0x0001, 1))) { - maxbuddies = aimutil_get16(tlv->value); - } + if (aim_gettlv(tlvlist, 0x0001, 1)) + maxbuddies = aim_gettlv16(tlvlist, 0x0001, 1); /* * TLV type 0x0002: Maximum number of watchers. @@ -114,12 +86,10 @@ faim_internal int aim_parse_buddyrights(struct aim_session_t *sess, * XXX: what the hell is a watcher? * */ - if ((tlv = aim_gettlv(tlvlist, 0x0002, 1))) { - maxwatchers = aimutil_get16(tlv->value); - } + if (aim_gettlv(tlvlist, 0x0002, 1)) + maxwatchers = aim_gettlv16(tlvlist, 0x0002, 1); - userfunc = aim_callhandler(command->conn, 0x0003, 0x0003); - if (userfunc) + if ((userfunc = aim_callhandler(command->conn, 0x0003, 0x0003))) ret = userfunc(sess, command, maxbuddies, maxwatchers); aim_freetlvchain(&tlvlist); diff --git a/aim_chat.c b/aim_chat.c index 85331ed..5af5728 100644 --- a/aim_chat.c +++ b/aim_chat.c @@ -173,23 +173,9 @@ faim_export unsigned long aim_chat_join(struct aim_session_t *sess, newpacket->lock = 0; aim_tx_enqueue(sess, newpacket); -#if 0 - { - struct aim_snac_t snac; - - snac.id = sess->snac_nextid; - snac.family = 0x0001; - snac.type = 0x0004; - snac.flags = 0x0000; - - snac.data = malloc(strlen(roomname)+1); - strcpy(snac.data, roomname); - - aim_newsnac(sess, &snac); - } + aim_cachesnac(sess, 0x0001, 0x0004, 0x0000, roomname, strlen(roomname)+1); -#endif - return (sess->snac_nextid++); + return sess->snac_nextid; } faim_internal int aim_chat_readroominfo(u_char *buf, struct aim_chat_roominfo *outinfo) @@ -240,7 +226,6 @@ faim_internal int aim_chat_parse_infoupdate(struct aim_session_t *sess, u_short tlvcount = 0; struct aim_tlvlist_t *tlvlist; char *roomdesc = NULL; - struct aim_tlv_t *tmptlv; unsigned short unknown_c9 = 0; unsigned long creationtime = 0; unsigned short maxmsglen = 0; @@ -277,12 +262,8 @@ faim_internal int aim_chat_parse_infoupdate(struct aim_session_t *sess, /* * Type 0x006f: Number of occupants. */ - if (aim_gettlv(tlvlist, 0x006f, 1)) { - struct aim_tlv_t *tmptlv; - tmptlv = aim_gettlv(tlvlist, 0x006f, 1); - - usercount = aimutil_get16(tmptlv->value); - } + if (aim_gettlv(tlvlist, 0x006f, 1)) + usercount = aim_gettlv16(tlvlist, 0x006f, 1); /* * Type 0x0073: Occupant list. @@ -304,26 +285,26 @@ faim_internal int aim_chat_parse_infoupdate(struct aim_session_t *sess, /* * Type 0x00c9: Unknown. (2 bytes) */ - if ((tmptlv = aim_gettlv(tlvlist, 0x00c9, 1))) - unknown_c9 = aimutil_get16(tmptlv->value); + if (aim_gettlv(tlvlist, 0x00c9, 1)) + unknown_c9 = aim_gettlv16(tlvlist, 0x00c9, 1); /* * Type 0x00ca: Creation time (4 bytes) */ - if ((tmptlv = aim_gettlv(tlvlist, 0x00ca, 1))) - creationtime = aimutil_get32(tmptlv->value); + if (aim_gettlv(tlvlist, 0x00ca, 1)) + creationtime = aim_gettlv32(tlvlist, 0x00ca, 1); /* * Type 0x00d1: Maximum Message Length */ - if ((tmptlv = aim_gettlv(tlvlist, 0x00d1, 1))) - maxmsglen = aimutil_get16(tmptlv->value); + if (aim_gettlv(tlvlist, 0x00d1, 1)) + maxmsglen = aim_gettlv16(tlvlist, 0x00d1, 1); /* * Type 0x00d2: Unknown. (2 bytes) */ - if ((tmptlv = aim_gettlv(tlvlist, 0x00d2, 1))) - unknown_d2 = aimutil_get16(tmptlv->value);; + if (aim_gettlv(tlvlist, 0x00d2, 1)) + unknown_d2 = aim_gettlv16(tlvlist, 0x00d2, 1); /* * Type 0x00d3: Room Description @@ -334,12 +315,11 @@ faim_internal int aim_chat_parse_infoupdate(struct aim_session_t *sess, /* * Type 0x00d5: Unknown. (1 byte) */ - if ((tmptlv = aim_gettlv(tlvlist, 0x00d5, 1))) - unknown_d5 = aimutil_get8(tmptlv->value);; + if (aim_gettlv(tlvlist, 0x00d5, 1)) + unknown_d5 = aim_gettlv8(tlvlist, 0x00d5, 1); - userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE); - if (userfunc) { + if ((userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE))) { ret = userfunc(sess, command, &roominfo, @@ -375,8 +355,7 @@ faim_internal int aim_chat_parse_joined(struct aim_session_t *sess, i += aim_extractuserinfo(command->data+i, &userinfo[curcount-1]); } - userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN); - if (userfunc) { + if ((userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN))) { ret = userfunc(sess, command, curcount, @@ -402,8 +381,7 @@ faim_internal int aim_chat_parse_leave(struct aim_session_t *sess, i += aim_extractuserinfo(command->data+i, &userinfo[curcount-1]); } - userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE); - if (userfunc) { + if ((userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE))) { ret = userfunc(sess, command, curcount, diff --git a/aim_chatnav.c b/aim_chatnav.c index 4c93af1..6d4ad42 100644 --- a/aim_chatnav.c +++ b/aim_chatnav.c @@ -14,18 +14,9 @@ faim_export unsigned long aim_chatnav_reqrights(struct aim_session_t *sess, struct aim_conn_t *conn) { - struct aim_snac_t snac; + aim_genericreq_n(sess, conn, 0x000d, 0x0002); - snac.id = aim_genericreq_n(sess, conn, 0x000d, 0x0002); - - snac.family = 0x000d; - snac.type = 0x0002; - snac.flags = 0x0000; - snac.data = NULL; - - aim_newsnac(sess, &snac); - - return (sess->snac_nextid); /* already incremented */ + return sess->snac_nextid; } faim_export unsigned long aim_chatnav_clientready(struct aim_session_t *sess, @@ -105,11 +96,7 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm * Type 0x0002: Maximum concurrent rooms. */ if (aim_gettlv(tlvlist, 0x0002, 1)) - { - struct aim_tlv_t *maxroomstlv; - maxroomstlv = aim_gettlv(tlvlist, 0x0002, 1); - maxrooms = aimutil_get8(maxroomstlv->value); - } + maxrooms = aim_gettlv8(tlvlist, 0x0002, 1); /* * Type 0x0003: Exchange information @@ -145,11 +132,9 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm * Type 0x0002: Unknown */ if (aim_gettlv(innerlist, 0x0002, 1)) { - struct aim_tlv_t *tmptlv; - unsigned short classperms = 0; + unsigned short classperms; - tmptlv = aim_gettlv(innerlist, 0x0002, 1); - classperms = aimutil_get16(tmptlv->value); + classperms = aim_gettlv16(innerlist, 0x0002, 1); printf("faim: class permissions %x\n", classperms); } @@ -201,12 +186,9 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm * */ if (aim_gettlv(innerlist, 0x00d5, 1)) { - struct aim_tlv_t *tmptlv; - unsigned char createperms = 0; + unsigned char createperms; - tmptlv = aim_gettlv(innerlist, 0x00d5, 1); - createperms = aimutil_get8(tmptlv->value); - + createperms = aim_gettlv8(innerlist, 0x00d5, 1); } /* @@ -315,7 +297,7 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm unsigned long createtime = 0; unsigned char createperms; int i, cklen; - struct aim_tlv_t *bigblock, *tmp; + struct aim_tlv_t *bigblock; i = 10; if (!(tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i))) { @@ -365,23 +347,23 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm if (aim_gettlv(innerlist, 0x006a, 1)) fqcn = aim_gettlv_str(innerlist, 0x006a, 1); - if ((tmp = aim_gettlv(innerlist, 0x00c9, 1))) - flags = aimutil_get16(tmp->value); + if (aim_gettlv(innerlist, 0x00c9, 1)) + flags = aim_gettlv16(innerlist, 0x00c9, 1); - if ((tmp = aim_gettlv(innerlist, 0x00ca, 1))) - createtime = aimutil_get32(tmp->value); + if (aim_gettlv(innerlist, 0x00ca, 1)) + createtime = aim_gettlv32(innerlist, 0x00ca, 1); - if ((tmp = aim_gettlv(innerlist, 0x00d1, 1))) - maxmsglen = aimutil_get16(tmp->value); + if (aim_gettlv(innerlist, 0x00d1, 1)) + maxmsglen = aim_gettlv16(innerlist, 0x00d1, 1); - if ((tmp = aim_gettlv(innerlist, 0x00d2, 1))) - maxoccupancy = aimutil_get16(tmp->value); + if (aim_gettlv(innerlist, 0x00d2, 1)) + maxoccupancy = aim_gettlv16(innerlist, 0x00d2, 1); if (aim_gettlv(innerlist, 0x00d3, 1)) name = aim_gettlv_str(innerlist, 0x00d3, 1); - if ((tmp = aim_gettlv(innerlist, 0x00d5, 1))) - createperms = aimutil_get8(tmp->value); + if (aim_gettlv(innerlist, 0x00d5, 1)) + createperms = aim_gettlv8(innerlist, 0x00d5, 1); if ((userfunc = aim_callhandler(command->conn, 0x000d, 0x0009))) { ret = userfunc(sess, command, snac->type, fqcn, instance, exchange, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck); @@ -417,7 +399,6 @@ faim_export unsigned long aim_chatnav_createroom(struct aim_session_t *sess, { struct command_tx_struct *newpacket; int i; - struct aim_snac_t snac; if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+12+strlen("invite")+strlen(name)))) return -1; @@ -445,15 +426,9 @@ faim_export unsigned long aim_chatnav_createroom(struct aim_session_t *sess, /* room name */ i+= aim_puttlv_str(newpacket->data+i, 0x00d3, strlen(name), name); - snac.id = sess->snac_nextid; - snac.family = 0x000d; - snac.type = 0x0008; - snac.flags = 0x0000; - snac.data = NULL; - - aim_newsnac(sess, &snac); + aim_cachesnac(sess, 0x000d, 0x0008, 0x0000, NULL, 0); aim_tx_enqueue(sess, newpacket); - return (sess->snac_nextid++); + return sess->snac_nextid; } diff --git a/aim_ft.c b/aim_ft.c index b47eef6..84ce4df 100644 --- a/aim_ft.c +++ b/aim_ft.c @@ -423,24 +423,6 @@ faim_export struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess, * n seconds of no connection. -- mid */ -#ifdef USE_SNAC_FOR_IMS - { - struct aim_snac_t snac; - - snac.id = sess->snac_nextid; - snac.family = 0x0004; - snac.type = 0x0006; - snac.flags = 0x0000; - - snac.data = malloc(strlen(destsn)+1); - memcpy(snac.data, destsn, strlen(destsn)+1); - - aim_newsnac(sess, &snac); - - aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */ - } -#endif - return (newconn); } @@ -1859,24 +1841,6 @@ faim_export struct aim_conn_t *aim_getfile_initiate(struct aim_session_t *sess, * n seconds of no connection. -- mid */ -#ifdef USE_SNAC_FOR_IMS - { - struct aim_snac_t snac; - - snac.id = sess->snac_nextid; - snac.family = 0x0004; - snac.type = 0x0006; - snac.flags = 0x0000; - - snac.data = malloc(strlen(destsn)+1); - memcpy(snac.data, destsn, strlen(destsn)+1); - - aim_newsnac(sess, &snac); - - aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */ - } -#endif - return newconn; } diff --git a/aim_im.c b/aim_im.c index 216d2c0..9d0cbd9 100644 --- a/aim_im.c +++ b/aim_im.c @@ -118,25 +118,10 @@ faim_export unsigned long aim_send_im(struct aim_session_t *sess, aim_tx_enqueue(sess, newpacket); -#ifdef USE_SNAC_FOR_IMS - { - struct aim_snac_t snac; + aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, destsn, strlen(destsn)+1); + aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */ - snac.id = sess->snac_nextid; - snac.family = 0x0004; - snac.type = 0x0006; - snac.flags = 0x0000; - - snac.data = malloc(strlen(destsn)+1); - memcpy(snac.data, destsn, strlen(destsn)+1); - - aim_newsnac(sess, &snac); - } - - aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */ -#endif - - return (sess->snac_nextid++); + return sess->snac_nextid; } faim_internal int aim_parse_outgoing_im_middle(struct aim_session_t *sess, @@ -467,14 +452,13 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess, struct aim_filetransfer_priv *ft; if (cook->data) { - struct aim_tlv_t *errortlv; - int errorcode = -1; + int errorcode = -1; /* XXX shouldnt this be 0? */ ft = (struct aim_filetransfer_priv *)cook->data; - if ((errortlv = aim_gettlv(list2, 0x000b, 1))) { - errorcode = aimutil_get16(errortlv->value); - } + if (aim_gettlv(list2, 0x000b, 1)) + errorcode = aim_gettlv16(list2, 0x000b, 1); + if (errorcode) { printf("faim: transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode); } else if (status == 0x0002) { /* connection accepted */ diff --git a/aim_info.c b/aim_info.c index 0abbcf5..396ddb9 100644 --- a/aim_info.c +++ b/aim_info.c @@ -10,7 +10,7 @@ #include struct aim_priv_inforeq { - char sn[MAXSNLEN]; + char sn[MAXSNLEN+1]; unsigned short infotype; }; @@ -20,6 +20,7 @@ faim_export unsigned long aim_getinfo(struct aim_session_t *sess, unsigned short infotype) { struct command_tx_struct *newpacket; + struct aim_priv_inforeq privdata; int i = 0; if (!sess || !conn || !sn) @@ -39,22 +40,11 @@ faim_export unsigned long aim_getinfo(struct aim_session_t *sess, newpacket->lock = 0; aim_tx_enqueue(sess, newpacket); - { - struct aim_snac_t snac; - - snac.id = sess->snac_nextid; - snac.family = 0x0002; - snac.type = 0x0005; - snac.flags = 0x0000; - - snac.data = malloc(sizeof(struct aim_priv_inforeq)); - strcpy(((struct aim_priv_inforeq *)snac.data)->sn, sn); - ((struct aim_priv_inforeq *)snac.data)->infotype = infotype; - - aim_newsnac(sess, &snac); - } + strncpy(privdata.sn, sn, sizeof(privdata.sn)); + privdata.infotype = infotype; + aim_cachesnac(sess, 0x0002, 0x0005, 0x0000, &privdata, sizeof(struct aim_priv_inforeq)); - return (sess->snac_nextid++); + return sess->snac_nextid; } faim_internal int aim_parse_locateerr(struct aim_session_t *sess, diff --git a/aim_misc.c b/aim_misc.c index 56e4a5b..368215a 100644 --- a/aim_misc.c +++ b/aim_misc.c @@ -267,7 +267,6 @@ faim_internal int aim_parse_bosrights(struct aim_session_t *sess, rxcallback_t userfunc = NULL; int ret=1; struct aim_tlvlist_t *tlvlist; - struct aim_tlv_t *tlv; unsigned short maxpermits = 0, maxdenies = 0; /* @@ -279,21 +278,18 @@ faim_internal int aim_parse_bosrights(struct aim_session_t *sess, /* * TLV type 0x0001: Maximum number of buddies on permit list. */ - if ((tlv = aim_gettlv(tlvlist, 0x0001, 1))) { - maxpermits = aimutil_get16(tlv->value); - } + if (aim_gettlv(tlvlist, 0x0001, 1)) + maxpermits = aim_gettlv16(tlvlist, 0x0001, 1); /* * TLV type 0x0002: Maximum number of buddies on deny list. * */ - if ((tlv = aim_gettlv(tlvlist, 0x0002, 1))) { - maxdenies = aimutil_get16(tlv->value); - } + if (aim_gettlv(tlvlist, 0x0002, 1)) + maxdenies = aim_gettlv16(tlvlist, 0x0002, 1); - userfunc = aim_callhandler(command->conn, 0x0009, 0x0003); - if (userfunc) - ret = userfunc(sess, command, maxpermits, maxdenies); + if ((userfunc = aim_callhandler(command->conn, 0x0009, 0x0003))) + ret = userfunc(sess, command, maxpermits, maxdenies); aim_freetlvchain(&tlvlist); diff --git a/aim_rxhandlers.c b/aim_rxhandlers.c index df0c499..10c9ee3 100644 --- a/aim_rxhandlers.c +++ b/aim_rxhandlers.c @@ -734,66 +734,45 @@ faim_internal int aim_parsemotd_middle(struct aim_session_t *sess, faim_internal int aim_handleredirect_middle(struct aim_session_t *sess, struct command_rx_struct *command, ...) { - struct aim_tlv_t *tmptlv = NULL; - int serviceid = 0x00; - unsigned char cookie[AIM_COOKIELEN]; + int serviceid = 0; + unsigned char *cookie = NULL; char *ip = NULL; rxcallback_t userfunc = NULL; struct aim_tlvlist_t *tlvlist; int ret = 1; - if (!(tlvlist = aim_readtlvchain(command->data+10, command->commandlen-10))) - { - printf("libfaim: major bug: unable to read tlvchain from redirect\n"); - return ret; - } - - if (!(tmptlv = aim_gettlv(tlvlist, 0x000d, 1))) - { - printf("libfaim: major bug: no service ID in tlvchain from redirect\n"); - aim_freetlvchain(&tlvlist); - return ret; - } - serviceid = aimutil_get16(tmptlv->value); - - if (!(ip = aim_gettlv_str(tlvlist, 0x0005, 1))) - { - printf("libfaim: major bug: no IP in tlvchain from redirect (service 0x%02x)\n", serviceid); - free(ip); - aim_freetlvchain(&tlvlist); - return ret; - } - - if (!(tmptlv = aim_gettlv(tlvlist, 0x0006, 1))) - { - printf("libfaim: major bug: no cookie in tlvchain from redirect (service 0x%02x)\n", serviceid); - free(ip); - aim_freetlvchain(&tlvlist); - return ret; - } - memcpy(cookie, tmptlv->value, AIM_COOKIELEN); - - if (serviceid == AIM_CONN_TYPE_CHAT) - { - /* - * Chat hack. - * - */ - userfunc = aim_callhandler(command->conn, 0x0001, 0x0005); - if (userfunc) - ret = userfunc(sess, command, serviceid, ip, cookie, sess->pendingjoin, (int)sess->pendingjoinexchange); + tlvlist = aim_readtlvchain(command->data+10, command->commandlen-10); + + if (aim_gettlv(tlvlist, 0x000d, 1)) + serviceid = aim_gettlv16(tlvlist, 0x000d, 1); + if (aim_gettlv(tlvlist, 0x0005, 1)) + ip = aim_gettlv_str(tlvlist, 0x0005, 1); + if (aim_gettlv(tlvlist, 0x0006, 1)) + cookie = aim_gettlv_str(tlvlist, 0x0006, 1); + + if ((serviceid == AIM_CONN_TYPE_CHAT) && sess->pendingjoin) { + + /* + * Chat hack. + * + */ + if ((userfunc = aim_callhandler(command->conn, 0x0001, 0x0005))) + ret = userfunc(sess, command, serviceid, ip, cookie, sess->pendingjoin, (int)sess->pendingjoinexchange); free(sess->pendingjoin); sess->pendingjoin = NULL; sess->pendingjoinexchange = 0; - } - else - { - userfunc = aim_callhandler(command->conn, 0x0001, 0x0005); - if (userfunc) - ret = userfunc(sess, command, serviceid, ip, cookie); - } + } else if (!serviceid || !ip || !cookie) { /* yeep! */ + ret = 1; + } else { + if ((userfunc = aim_callhandler(command->conn, 0x0001, 0x0005))) + ret = userfunc(sess, command, serviceid, ip, cookie); + } + + if (ip) + free(ip); + if (cookie) + free(cookie); - free(ip); aim_freetlvchain(&tlvlist); return ret; @@ -829,25 +808,24 @@ faim_internal int aim_negchan_middle(struct aim_session_t *sess, struct aim_tlvlist_t *tlvlist; char *msg = NULL; unsigned short code = 0; - struct aim_tlv_t *tmptlv; rxcallback_t userfunc = NULL; int ret = 1; tlvlist = aim_readtlvchain(command->data, command->commandlen); - if ((tmptlv = aim_gettlv(tlvlist, 0x0009, 1))) - code = aimutil_get16(tmptlv->value); + if (aim_gettlv(tlvlist, 0x0009, 1)) + code = aim_gettlv16(tlvlist, 0x0009, 1); - if ((tmptlv = aim_gettlv(tlvlist, 0x000b, 1))) + if (aim_gettlv(tlvlist, 0x000b, 1)) msg = aim_gettlv_str(tlvlist, 0x000b, 1); - userfunc = aim_callhandler(command->conn, - AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR); - if (userfunc) + if ((userfunc = aim_callhandler(command->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR))) ret = userfunc(sess, command, code, msg); aim_freetlvchain(&tlvlist); - free(msg); + + if (msg) + free(msg); return ret; } diff --git a/aim_search.c b/aim_search.c index 1963592..a8c4e1c 100644 --- a/aim_search.c +++ b/aim_search.c @@ -28,20 +28,8 @@ faim_export unsigned long aim_usersearch_address(struct aim_session_t *sess, aim_tx_enqueue(sess, newpacket); - { - struct aim_snac_t snac; - - snac.id = sess->snac_nextid; - snac.family = 0x000a; - snac.type = 0x0002; - snac.flags = 0x0000; + aim_cachesnac(sess, 0x000a, 0x0002, 0x0000, address, strlen(address)+1); - snac.data = malloc(strlen(address)+1); - memcpy(snac.data, address, strlen(address)+1); - - aim_newsnac(sess, &snac); - } - - return (sess->snac_nextid++); + return sess->snac_nextid; } diff --git a/aim_snac.c b/aim_snac.c index 64b884a..ae46e47 100644 --- a/aim_snac.c +++ b/aim_snac.c @@ -30,6 +30,25 @@ faim_internal void aim_initsnachash(struct aim_session_t *sess) return; } +faim_internal unsigned long aim_cachesnac(struct aim_session_t *sess, + const unsigned short family, + const unsigned short type, + const unsigned short flags, + const void *data, const int datalen) +{ + struct aim_snac_t snac; + + snac.id = sess->snac_nextid++; + snac.family = family; + snac.type = type; + snac.flags = flags; + + snac.data = malloc(datalen); + memcpy(snac.data, data, datalen); + + return aim_newsnac(sess, &snac); +} + /* * Clones the passed snac structure and caches it in the * list/hash. diff --git a/faim/aim.h b/faim/aim.h index 0c96008..1bd0014 100644 --- a/faim/aim.h +++ b/faim/aim.h @@ -505,6 +505,7 @@ struct aim_snac_t { }; faim_internal void aim_initsnachash(struct aim_session_t *sess); faim_internal unsigned long aim_newsnac(struct aim_session_t *, struct aim_snac_t *newsnac); +faim_internal unsigned long aim_cachesnac(struct aim_session_t *sess, const unsigned short family, const unsigned short type, const unsigned short flags, const void *data, const int datalen); faim_internal struct aim_snac_t *aim_remsnac(struct aim_session_t *, u_long id); faim_internal int aim_cleansnacs(struct aim_session_t *, int maxage); faim_internal int aim_putsnac(u_char *, int, int, int, u_long);