4 * The functions here are responsible for requesting and parsing information-
12 struct aim_priv_inforeq {
14 unsigned short infotype;
17 faim_export unsigned long aim_getinfo(struct aim_session_t *sess,
18 struct aim_conn_t *conn,
20 unsigned short infotype)
22 struct command_tx_struct *newpacket;
23 struct aim_priv_inforeq privdata;
26 if (!sess || !conn || !sn)
29 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 12+1+strlen(sn))))
34 i = aim_putsnac(newpacket->data, 0x0002, 0x0005, 0x0000, sess->snac_nextid);
36 i += aimutil_put16(newpacket->data+i, infotype);
37 i += aimutil_put8(newpacket->data+i, strlen(sn));
38 i += aimutil_putstr(newpacket->data+i, sn, strlen(sn));
41 aim_tx_enqueue(sess, newpacket);
43 strncpy(privdata.sn, sn, sizeof(privdata.sn));
44 privdata.infotype = infotype;
45 aim_cachesnac(sess, 0x0002, 0x0005, 0x0000, &privdata, sizeof(struct aim_priv_inforeq));
47 return sess->snac_nextid;
50 faim_internal int aim_parse_locateerr(struct aim_session_t *sess,
51 struct command_rx_struct *command)
53 u_long snacid = 0x000000000;
54 struct aim_snac_t *snac = NULL;
56 rxcallback_t userfunc = NULL;
58 unsigned short reason = 0;
61 * Get SNAC from packet and look it up
62 * the list of unrepliedto/outstanding
66 snacid = aimutil_get32(command->data+6);
67 snac = aim_remsnac(sess, snacid);
70 printf("faim: locerr: got an locate-failed error on an unknown SNAC ID! (%08lx)\n", snacid);
75 reason = aimutil_get16(command->data+10);
80 userfunc = aim_callhandler(command->conn, 0x0002, 0x0001);
82 ret = userfunc(sess, command, dest, reason);
97 u_char aim_caps[6][16] = {
100 {0x09, 0x46, 0x13, 0x46, 0x4c, 0x7f, 0x11, 0xd1,
101 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
104 {0x09, 0x46, 0x13, 0x41, 0x4c, 0x7f, 0x11, 0xd1,
105 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
108 {0x09, 0x46, 0x13, 0x45, 0x4c, 0x7f, 0x11, 0xd1,
109 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
112 {0x74, 0x8f, 0x24, 0x20, 0x62, 0x87, 0x11, 0xd1,
113 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
116 {0x09, 0x46, 0x13, 0x48, 0x4c, 0x7f, 0x11, 0xd1,
117 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
120 {0x09, 0x46, 0x13, 0x43, 0x4c, 0x7f, 0x11, 0xd1,
121 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}
124 faim_internal unsigned short aim_getcap(unsigned char *capblock, int buflen)
130 while (offset < buflen) {
131 for(y=0; y < (sizeof(aim_caps)/0x10); y++) {
132 if (memcmp(&aim_caps[y], capblock+offset, 0x10) == 0) {
134 case 0: ret |= AIM_CAPS_BUDDYICON; break;
135 case 1: ret |= AIM_CAPS_VOICE; break;
136 case 2: ret |= AIM_CAPS_IMIMAGE; break;
137 case 3: ret |= AIM_CAPS_CHAT; break;
138 case 4: ret |= AIM_CAPS_GETFILE; break;
139 case 5: ret |= AIM_CAPS_SENDFILE; break;
140 default: ret |= 0xff00; break;
149 faim_internal int aim_putcap(unsigned char *capblock, int buflen, u_short caps)
156 if ((caps & AIM_CAPS_BUDDYICON) && (offset < buflen)) {
157 memcpy(capblock+offset, aim_caps[0], sizeof(aim_caps[0]));
158 offset += sizeof(aim_caps[1]);
160 if ((caps & AIM_CAPS_VOICE) && (offset < buflen)) {
161 memcpy(capblock+offset, aim_caps[1], sizeof(aim_caps[1]));
162 offset += sizeof(aim_caps[1]);
164 if ((caps & AIM_CAPS_IMIMAGE) && (offset < buflen)) {
165 memcpy(capblock+offset, aim_caps[2], sizeof(aim_caps[2]));
166 offset += sizeof(aim_caps[2]);
168 if ((caps & AIM_CAPS_CHAT) && (offset < buflen)) {
169 memcpy(capblock+offset, aim_caps[3], sizeof(aim_caps[3]));
170 offset += sizeof(aim_caps[3]);
172 if ((caps & AIM_CAPS_GETFILE) && (offset < buflen)) {
173 memcpy(capblock+offset, aim_caps[4], sizeof(aim_caps[4]));
174 offset += sizeof(aim_caps[4]);
176 if ((caps & AIM_CAPS_SENDFILE) && (offset < buflen)) {
177 memcpy(capblock+offset, aim_caps[5], sizeof(aim_caps[5]));
178 offset += sizeof(aim_caps[5]);
185 * AIM is fairly regular about providing user info. This
186 * is a generic routine to extract it in its standard form.
188 faim_internal int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinfo)
198 if (!buf || !outinfo)
201 /* Clear out old data first */
202 memset(outinfo, 0x00, sizeof(struct aim_userinfo_s));
205 * Screen name. Stored as an unterminated string prepended
206 * with an unsigned byte containing its length.
208 if (buf[i] < MAXSNLEN) {
209 memcpy(outinfo->sn, &(buf[i+1]), buf[i]);
210 outinfo->sn[(int)buf[i]] = '\0';
212 memcpy(outinfo->sn, &(buf[i+1]), MAXSNLEN-1);
213 outinfo->sn[MAXSNLEN] = '\0';
218 * Warning Level. Stored as an unsigned short.
220 outinfo->warnlevel = aimutil_get16(&buf[i]);
224 * TLV Count. Unsigned short representing the number of
225 * Type-Length-Value triples that follow.
227 tlvcnt = aimutil_get16(&buf[i]);
231 * Parse out the Type-Length-Value triples as they're found.
233 while (curtlv < tlvcnt) {
235 curtype = aimutil_get16(&buf[i]);
238 * Type = 0x0000: Invalid
240 * AOL has been trying to throw these in just to break us.
241 * They're real nice guys over there at AOL.
243 * Just skip the two zero bytes and continue on. (This doesn't
244 * count towards tlvcnt!)
252 * Type = 0x0001: User flags
254 * Specified as any of the following bitwise ORed together:
255 * 0x0001 Trial (user less than 60days)
256 * 0x0002 Unknown bit 2
257 * 0x0004 AOL Main Service user
258 * 0x0008 Unknown bit 4
259 * 0x0010 Free (AIM) user
262 * In some odd cases, we can end up with more
263 * than one of these. We only want the first,
264 * as the others may not be something we want.
268 if (tlv1) /* use only the first */
270 outinfo->flags = aimutil_get16(&buf[i+4]);
275 * Type = 0x0002: Member-Since date.
277 * The time/date that the user originally
278 * registered for the service, stored in
282 outinfo->membersince = aimutil_get32(&buf[i+4]);
286 * Type = 0x0003: On-Since date.
288 * The time/date that the user started
289 * their current session, stored in time_t
293 outinfo->onlinesince = aimutil_get32(&buf[i+4]);
297 * Type = 0x0004: Idle time.
299 * Number of seconds since the user
300 * actively used the service.
303 outinfo->idletime = aimutil_get16(&buf[i+4]);
307 * Type = 0x0006: ICQ Online Status
309 * ICQ's Away/DND/etc "enriched" status
310 * Some decoding of values done by Scott <darkagl@pcnet.com>
313 outinfo->icqinfo.status = aimutil_get16(buf+i+2+2+2);
320 * ICQ User IP Address.
321 * Ahh, the joy of ICQ security.
324 outinfo->icqinfo.ipaddr = aimutil_get32(&buf[i+4]);
329 * random crap containing the IP address,
330 * apparently a port number, and some Other Stuff.
334 memcpy(outinfo->icqinfo.crap, &buf[i+4], 0x25);
340 * Capability information. Not real sure of
341 * actual decoding. See comment on aim_bos_setprofile()
342 * in aim_misc.c about the capability block, its the same.
348 len = aimutil_get16(buf+i+2);
352 outinfo->capabilities = aim_getcap(buf+i+4, len);
359 * Unknown. Always of zero length, and always only
369 * Type = 0x000f: Session Length. (AIM)
370 * Type = 0x0010: Session Length. (AOL)
372 * The duration, in seconds, of the user's
375 * Which TLV type this comes in depends
376 * on the service the user is using (AIM or AOL).
381 outinfo->sessionlen = aimutil_get32(&buf[i+4]);
385 * Reaching here indicates that either AOL has
386 * added yet another TLV for us to deal with,
387 * or the parsing has gone Terribly Wrong.
389 * Either way, inform the owner and attempt
395 int len,z = 0, y = 0, x = 0;
397 printf("faim: userinfo: **warning: unexpected TLV:\n");
398 printf("faim: userinfo: sn =%s\n", outinfo->sn);
399 printf("faim: userinfo: curtlv=0x%04x\n", curtlv);
400 printf("faim: userinfo: type =0x%04x\n",aimutil_get16(&buf[i]));
401 printf("faim: userinfo: length=0x%04x\n", len = aimutil_get16(&buf[i+2]));
402 printf("faim: userinfo: data: \n");
405 x = sprintf(tmpstr, "faim: userinfo: ");
406 for (y = 0; y < 8; y++)
410 sprintf(tmpstr+x, "%02x ", buf[i+4+z]);
417 printf("%s\n", tmpstr);
423 * No matter what, TLV triplets should always look like this:
427 * u_char data[length];
431 i += (2 + 2 + aimutil_get16(&buf[i+2]));
440 * Oncoming Buddy notifications contain a subset of the
441 * user information structure. Its close enough to run
442 * through aim_extractuserinfo() however.
445 faim_internal int aim_parse_oncoming_middle(struct aim_session_t *sess,
446 struct command_rx_struct *command)
448 struct aim_userinfo_s userinfo;
450 rxcallback_t userfunc=NULL;
453 i += aim_extractuserinfo(command->data+i, &userinfo);
455 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING);
457 i = userfunc(sess, command, &userinfo);
463 * Offgoing Buddy notifications contain no useful
464 * information other than the name it applies to.
467 faim_internal int aim_parse_offgoing_middle(struct aim_session_t *sess,
468 struct command_rx_struct *command)
472 rxcallback_t userfunc=NULL;
474 strncpy(sn, (char *)command->data+11, (int)command->data[10]);
475 sn[(int)command->data[10]] = '\0';
477 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING);
479 i = userfunc(sess, command, sn);
485 * This parses the user info stuff out all nice and pretty then calls
486 * the higher-level callback (in the user app).
489 faim_internal int aim_parse_userinfo_middle(struct aim_session_t *sess,
490 struct command_rx_struct *command)
492 struct aim_userinfo_s userinfo;
493 char *text_encoding = NULL;
496 rxcallback_t userfunc=NULL;
497 struct aim_tlvlist_t *tlvlist;
498 struct aim_snac_t *origsnac = NULL;
500 struct aim_priv_inforeq *inforeq;
502 snacid = aimutil_get32(&command->data[6]);
503 origsnac = aim_remsnac(sess, snacid);
505 if (!origsnac || !origsnac->data) {
506 printf("faim: parse_userinfo_middle: major problem: no snac stored!\n");
510 inforeq = (struct aim_priv_inforeq *)origsnac->data;
512 switch (inforeq->infotype) {
513 case AIM_GETINFO_GENERALINFO:
514 case AIM_GETINFO_AWAYMESSAGE:
518 * extractuserinfo will give us the basic metaTLV information
520 i += aim_extractuserinfo(command->data+i, &userinfo);
523 * However, in this command, there's usually more TLVs following...
525 tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
528 * Depending on what informational text was requested, different
529 * TLVs will appear here.
531 * Profile will be 1 and 2, away message will be 3 and 4.
533 if (aim_gettlv(tlvlist, 0x0001, 1)) {
534 text_encoding = aim_gettlv_str(tlvlist, 0x0001, 1);
535 text = aim_gettlv_str(tlvlist, 0x0002, 1);
536 } else if (aim_gettlv(tlvlist, 0x0003, 1)) {
537 text_encoding = aim_gettlv_str(tlvlist, 0x0003, 1);
538 text = aim_gettlv_str(tlvlist, 0x0004, 1);
541 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO);
553 aim_freetlvchain(&tlvlist);
556 printf("faim: parse_userinfo_middle: unknown infotype in request! (0x%04x)\n", inforeq->infotype);
562 free(origsnac->data);
570 * Inverse of aim_extractuserinfo()
572 faim_internal int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info)
574 int i = 0, numtlv = 0;
575 struct aim_tlvlist_t *tlvlist = NULL;
580 i += aimutil_put8(buf+i, strlen(info->sn));
581 i += aimutil_putstr(buf+i, info->sn, strlen(info->sn));
583 i += aimutil_put16(buf+i, info->warnlevel);
586 aim_addtlvtochain16(&tlvlist, 0x0001, info->flags);
589 aim_addtlvtochain32(&tlvlist, 0x0002, info->membersince);
592 aim_addtlvtochain32(&tlvlist, 0x0003, info->onlinesince);
595 aim_addtlvtochain16(&tlvlist, 0x0004, info->idletime);
598 #if ICQ_OSCAR_SUPPORT
599 if(atoi(info->sn) != 0) {
600 aim_addtlvtochain16(&tlvlist, 0x0006, info->icqinfo.status);
601 aim_addtlvtochain32(&tlvlist, 0x000a, info->icqinfo.ipaddr);
605 aim_addtlvtochain_caps(&tlvlist, 0x000d, info->capabilities);
608 aim_addtlvtochain32(&tlvlist, (unsigned short)((info->flags)&AIM_FLAG_AOL?0x0010:0x000f), info->sessionlen);
611 i += aimutil_put16(buf+i, numtlv); /* tlvcount */
612 i += aim_writetlvchain(buf+i, buflen-i, &tlvlist); /* tlvs */
613 aim_freetlvchain(&tlvlist);
618 faim_export int aim_sendbuddyoncoming(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_userinfo_s *info)
620 struct command_tx_struct *tx;
623 if (!sess || !conn || !info)
626 if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152)))
631 i += aimutil_put16(tx->data+i, 0x0003);
632 i += aimutil_put16(tx->data+i, 0x000b);
633 i += aimutil_put16(tx->data+i, 0x0000);
634 i += aimutil_put16(tx->data+i, 0x0000);
635 i += aimutil_put16(tx->data+i, 0x0000);
637 i += aim_putuserinfo(tx->data+i, tx->commandlen-i, info);
641 aim_tx_enqueue(sess, tx);
646 faim_export int aim_sendbuddyoffgoing(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn)
648 struct command_tx_struct *tx;
651 if (!sess || !conn || !sn)
654 if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+1+strlen(sn))))
659 i += aimutil_put16(tx->data+i, 0x0003);
660 i += aimutil_put16(tx->data+i, 0x000c);
661 i += aimutil_put16(tx->data+i, 0x0000);
662 i += aimutil_put16(tx->data+i, 0x0000);
663 i += aimutil_put16(tx->data+i, 0x0000);
665 i += aimutil_put8(tx->data+i, strlen(sn));
666 i += aimutil_putstr(tx->data+i, sn, strlen(sn));
669 aim_tx_enqueue(sess, tx);