X-Git-Url: http://andersk.mit.edu/gitweb/libfaim.git/blobdiff_plain/b69540e3cf15a403137cb89bbc36ef7450945f83..89bce17768d14f77b0a3fa612d56372f3b6ded5c:/aim_info.c diff --git a/aim_info.c b/aim_info.c index 88f07fc..0abbcf5 100644 --- a/aim_info.c +++ b/aim_info.c @@ -14,10 +14,10 @@ struct aim_priv_inforeq { unsigned short infotype; }; -u_long aim_getinfo(struct aim_session_t *sess, - struct aim_conn_t *conn, - const char *sn, - unsigned short infotype) +faim_export unsigned long aim_getinfo(struct aim_session_t *sess, + struct aim_conn_t *conn, + const char *sn, + unsigned short infotype) { struct command_tx_struct *newpacket; int i = 0; @@ -57,6 +57,49 @@ u_long aim_getinfo(struct aim_session_t *sess, return (sess->snac_nextid++); } +faim_internal int aim_parse_locateerr(struct aim_session_t *sess, + struct command_rx_struct *command) +{ + u_long snacid = 0x000000000; + struct aim_snac_t *snac = NULL; + int ret = 0; + rxcallback_t userfunc = NULL; + char *dest; + unsigned short reason = 0; + + /* + * Get SNAC from packet and look it up + * the list of unrepliedto/outstanding + * SNACs. + * + */ + snacid = aimutil_get32(command->data+6); + snac = aim_remsnac(sess, snacid); + + if (!snac) { + printf("faim: locerr: got an locate-failed error on an unknown SNAC ID! (%08lx)\n", snacid); + dest = NULL; + } else + dest = snac->data; + + reason = aimutil_get16(command->data+10); + + /* + * Call client. + */ + userfunc = aim_callhandler(command->conn, 0x0002, 0x0001); + if (userfunc) + ret = userfunc(sess, command, dest, reason); + else + ret = 0; + + if (snac) { + free(snac->data); + free(snac); + } + + return ret; +} /* * Capability blocks. @@ -88,7 +131,7 @@ u_char aim_caps[6][16] = { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00} }; -u_short aim_getcap(unsigned char *capblock, int buflen) +faim_internal unsigned short aim_getcap(unsigned char *capblock, int buflen) { u_short ret = 0; int y; @@ -113,7 +156,7 @@ u_short aim_getcap(unsigned char *capblock, int buflen) return ret; } -int aim_putcap(unsigned char *capblock, int buflen, u_short caps) +faim_internal int aim_putcap(unsigned char *capblock, int buflen, u_short caps) { int offset = 0; @@ -152,13 +195,14 @@ int aim_putcap(unsigned char *capblock, int buflen, u_short caps) * AIM is fairly regular about providing user info. This * is a generic routine to extract it in its standard form. */ -int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinfo) +faim_internal int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinfo) { int i = 0; int tlvcnt = 0; int curtlv = 0; int tlv1 = 0; u_short curtype; + int lastvalid; if (!buf || !outinfo) @@ -171,8 +215,13 @@ int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinfo) * Screen name. Stored as an unterminated string prepended * with an unsigned byte containing its length. */ - memcpy(outinfo->sn, &(buf[i+1]), buf[i]); - outinfo->sn[(int)buf[i]] = '\0'; + if (buf[i] < MAXSNLEN) { + memcpy(outinfo->sn, &(buf[i+1]), buf[i]); + outinfo->sn[(int)buf[i]] = '\0'; + } else { + memcpy(outinfo->sn, &(buf[i+1]), MAXSNLEN-1); + outinfo->sn[MAXSNLEN] = '\0'; + } i = 1 + (int)buf[i]; /* @@ -191,163 +240,208 @@ int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinfo) /* * Parse out the Type-Length-Value triples as they're found. */ - while (curtlv < tlvcnt) - { - curtype = aimutil_get16(&buf[i]); - switch (curtype) - { - /* - * Type = 0x0001: Member Class. - * - * Specified as any of the following bitwise ORed together: - * 0x0001 Trial (user less than 60days) - * 0x0002 Unknown bit 2 - * 0x0004 AOL Main Service user - * 0x0008 Unknown bit 4 - * 0x0010 Free (AIM) user - * 0x0020 Away - * - * In some odd cases, we can end up with more - * than one of these. We only want the first, - * as the others may not be something we want. - * - */ - case 0x0001: - if (tlv1) /* use only the first */ - break; - outinfo->class = aimutil_get16(&buf[i+4]); - tlv1++; - break; - - /* - * Type = 0x0002: Member-Since date. - * - * The time/date that the user originally - * registered for the service, stored in - * time_t format - */ - case 0x0002: - outinfo->membersince = aimutil_get32(&buf[i+4]); - break; - - /* - * Type = 0x0003: On-Since date. - * - * The time/date that the user started - * their current session, stored in time_t - * format. - */ - case 0x0003: - outinfo->onlinesince = aimutil_get32(&buf[i+4]); - break; + while (curtlv < tlvcnt) { + lastvalid = 1; + curtype = aimutil_get16(&buf[i]); + switch (curtype) { + /* + * Type = 0x0000: Invalid + * + * AOL has been trying to throw these in just to break us. + * They're real nice guys over there at AOL. + * + * Just skip the two zero bytes and continue on. (This doesn't + * count towards tlvcnt!) + */ + case 0x0000: + lastvalid = 0; + i += 2; + break; - /* - * Type = 0x0004: Idle time. - * - * Number of seconds since the user - * actively used the service. - */ - case 0x0004: - outinfo->idletime = aimutil_get16(&buf[i+4]); - break; + /* + * Type = 0x0001: User flags + * + * Specified as any of the following bitwise ORed together: + * 0x0001 Trial (user less than 60days) + * 0x0002 Unknown bit 2 + * 0x0004 AOL Main Service user + * 0x0008 Unknown bit 4 + * 0x0010 Free (AIM) user + * 0x0020 Away + * + * In some odd cases, we can end up with more + * than one of these. We only want the first, + * as the others may not be something we want. + * + */ + case 0x0001: + if (tlv1) /* use only the first */ + break; + outinfo->flags = aimutil_get16(&buf[i+4]); + tlv1++; + break; + + /* + * Type = 0x0002: Member-Since date. + * + * The time/date that the user originally + * registered for the service, stored in + * time_t format + */ + case 0x0002: + outinfo->membersince = aimutil_get32(&buf[i+4]); + break; + + /* + * Type = 0x0003: On-Since date. + * + * The time/date that the user started + * their current session, stored in time_t + * format. + */ + case 0x0003: + outinfo->onlinesince = aimutil_get32(&buf[i+4]); + break; + + /* + * Type = 0x0004: Idle time. + * + * Number of seconds since the user + * actively used the service. + */ + case 0x0004: + outinfo->idletime = aimutil_get16(&buf[i+4]); + break; + + /* + * Type = 0x0006: ICQ Online Status + * + * ICQ's Away/DND/etc "enriched" status + * Some decoding of values done by Scott + */ + case 0x0006: + outinfo->icqinfo.status = aimutil_get16(buf+i+2+2+2); + break; - /* - * Type = 0x000d - * - * Capability information. Not real sure of - * actual decoding. See comment on aim_bos_setprofile() - * in aim_misc.c about the capability block, its the same. - * - */ - case 0x000d: - { - int len; - len = aimutil_get16(buf+i+2); - if (!len) - break; - - outinfo->capabilities = aim_getcap(buf+i+4, len); - } - break; - /* - * Type = 0x000e - * - * Unknown. Always of zero length, and always only - * on AOL users. - * - * Ignore. - * - */ - case 0x000e: - break; - - /* - * Type = 0x000f: Session Length. (AIM) - * Type = 0x0010: Session Length. (AOL) - * - * The duration, in seconds, of the user's - * current session. - * - * Which TLV type this comes in depends - * on the service the user is using (AIM or AOL). - * - */ - case 0x000f: - case 0x0010: - outinfo->sessionlen = aimutil_get32(&buf[i+4]); - break; + /* + * Type = 0x000a + * + * ICQ User IP Address. + * Ahh, the joy of ICQ security. + */ + case 0x000a: + outinfo->icqinfo.ipaddr = aimutil_get32(&buf[i+4]); + break; - /* - * Reaching here indicates that either AOL has - * added yet another TLV for us to deal with, - * or the parsing has gone Terribly Wrong. - * - * Either way, inform the owner and attempt - * recovery. - * - */ - default: - { - int len,z = 0, y = 0, x = 0; - char tmpstr[80]; - printf("faim: userinfo: **warning: unexpected TLV:\n"); - printf("faim: userinfo: sn =%s\n", outinfo->sn); - printf("faim: userinfo: curtlv=0x%04x\n", curtlv); - printf("faim: userinfo: type =0x%04x\n",aimutil_get16(&buf[i])); - printf("faim: userinfo: length=0x%04x\n", len = aimutil_get16(&buf[i+2])); - printf("faim: userinfo: data: \n"); - while (zicqinfo.crap, &buf[i+4], 0x25); + break; + + /* + * Type = 0x000d + * + * Capability information. Not real sure of + * actual decoding. See comment on aim_bos_setprofile() + * in aim_misc.c about the capability block, its the same. + * + */ + case 0x000d: + { + int len; + len = aimutil_get16(buf+i+2); + if (!len) break; - } + + outinfo->capabilities = aim_getcap(buf+i+4, len); + } + break; + /* - * No matter what, TLV triplets should always look like this: + * Type = 0x000e + * + * Unknown. Always of zero length, and always only + * on AOL users. * - * u_short type; - * u_short length; - * u_char data[length]; + * Ignore. * */ - i += (2 + 2 + aimutil_get16(&buf[i+2])); + case 0x000e: + break; + /* + * Type = 0x000f: Session Length. (AIM) + * Type = 0x0010: Session Length. (AOL) + * + * The duration, in seconds, of the user's + * current session. + * + * Which TLV type this comes in depends + * on the service the user is using (AIM or AOL). + * + */ + case 0x000f: + case 0x0010: + outinfo->sessionlen = aimutil_get32(&buf[i+4]); + break; + + /* + * Reaching here indicates that either AOL has + * added yet another TLV for us to deal with, + * or the parsing has gone Terribly Wrong. + * + * Either way, inform the owner and attempt + * recovery. + * + */ + default: + { + int len,z = 0, y = 0, x = 0; + char tmpstr[80]; + printf("faim: userinfo: **warning: unexpected TLV:\n"); + printf("faim: userinfo: sn =%s\n", outinfo->sn); + printf("faim: userinfo: curtlv=0x%04x\n", curtlv); + printf("faim: userinfo: type =0x%04x\n",aimutil_get16(&buf[i])); + printf("faim: userinfo: length=0x%04x\n", len = aimutil_get16(&buf[i+2])); + printf("faim: userinfo: data: \n"); + while (zdata+11, (int)command->data[10]); + strncpy(sn, (char *)command->data+11, (int)command->data[10]); sn[(int)command->data[10]] = '\0'; userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING); @@ -402,8 +496,8 @@ int aim_parse_offgoing_middle(struct aim_session_t *sess, * the higher-level callback (in the user app). * */ -int aim_parse_userinfo_middle(struct aim_session_t *sess, - struct command_rx_struct *command) +faim_internal int aim_parse_userinfo_middle(struct aim_session_t *sess, + struct command_rx_struct *command) { struct aim_userinfo_s userinfo; char *text_encoding = NULL; @@ -485,9 +579,9 @@ int aim_parse_userinfo_middle(struct aim_session_t *sess, /* * Inverse of aim_extractuserinfo() */ -int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info) +faim_internal int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info) { - int i = 0; + int i = 0, numtlv = 0; struct aim_tlvlist_t *tlvlist = NULL; if (!buf || !info) @@ -498,22 +592,40 @@ int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info) i += aimutil_put16(buf+i, info->warnlevel); - /* XXX: we only put down five */ - i += aimutil_put16(buf+i, 5); - aim_addtlvtochain16(&tlvlist, 0x0001, info->class); + + aim_addtlvtochain16(&tlvlist, 0x0001, info->flags); + numtlv++; + aim_addtlvtochain32(&tlvlist, 0x0002, info->membersince); + numtlv++; + aim_addtlvtochain32(&tlvlist, 0x0003, info->onlinesince); + numtlv++; + aim_addtlvtochain16(&tlvlist, 0x0004, info->idletime); - /* XXX: should put caps here */ - aim_addtlvtochain32(&tlvlist, (info->class)&AIM_CLASS_AOL?0x0010:0x000f, info->sessionlen); - - i += aim_writetlvchain(buf+i, buflen-i, &tlvlist); + numtlv++; + +#if ICQ_OSCAR_SUPPORT + if(atoi(info->sn) != 0) { + aim_addtlvtochain16(&tlvlist, 0x0006, info->icqinfo.status); + aim_addtlvtochain32(&tlvlist, 0x000a, info->icqinfo.ipaddr); + } +#endif + + aim_addtlvtochain_caps(&tlvlist, 0x000d, info->capabilities); + numtlv++; + + aim_addtlvtochain32(&tlvlist, (unsigned short)((info->flags)&AIM_FLAG_AOL?0x0010:0x000f), info->sessionlen); + numtlv++; + + i += aimutil_put16(buf+i, numtlv); /* tlvcount */ + i += aim_writetlvchain(buf+i, buflen-i, &tlvlist); /* tlvs */ aim_freetlvchain(&tlvlist); - + return i; } -int aim_sendbuddyoncoming(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_userinfo_s *info) +faim_export int aim_sendbuddyoncoming(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_userinfo_s *info) { struct command_tx_struct *tx; int i = 0; @@ -541,7 +653,7 @@ int aim_sendbuddyoncoming(struct aim_session_t *sess, struct aim_conn_t *conn, s return 0; } -int aim_sendbuddyoffgoing(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn) +faim_export int aim_sendbuddyoffgoing(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn) { struct command_tx_struct *tx; int i = 0;