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[8][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},
123 /* Saves stock portfolios */
124 {0x09, 0x46, 0x13, 0x47, 0x4c, 0x7f, 0x11, 0xd1,
125 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
128 {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1,
129 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
132 faim_internal unsigned short aim_getcap(unsigned char *capblock, int buflen)
139 while (offset < buflen) {
141 for(y=0; y < (sizeof(aim_caps)/0x10); y++) {
142 if (memcmp(&aim_caps[y], capblock+offset, 0x10) == 0) {
144 case 0: ret |= AIM_CAPS_BUDDYICON; identified++; break;
145 case 1: ret |= AIM_CAPS_VOICE; identified++; break;
146 case 2: ret |= AIM_CAPS_IMIMAGE; identified++; break;
147 case 3: ret |= AIM_CAPS_CHAT; identified++; break;
148 case 4: ret |= AIM_CAPS_GETFILE; identified++; break;
149 case 5: ret |= AIM_CAPS_SENDFILE; identified++; break;
150 case 6: ret |= AIM_CAPS_GAMES; identified++; break;
151 case 7: ret |= AIM_CAPS_SAVESTOCKS; identified++; break;
156 printf("faim: unknown capability!\n");
165 faim_internal int aim_putcap(unsigned char *capblock, int buflen, u_short caps)
172 if ((caps & AIM_CAPS_BUDDYICON) && (offset < buflen)) {
173 memcpy(capblock+offset, aim_caps[0], sizeof(aim_caps[0]));
174 offset += sizeof(aim_caps[1]);
176 if ((caps & AIM_CAPS_VOICE) && (offset < buflen)) {
177 memcpy(capblock+offset, aim_caps[1], sizeof(aim_caps[1]));
178 offset += sizeof(aim_caps[1]);
180 if ((caps & AIM_CAPS_IMIMAGE) && (offset < buflen)) {
181 memcpy(capblock+offset, aim_caps[2], sizeof(aim_caps[2]));
182 offset += sizeof(aim_caps[2]);
184 if ((caps & AIM_CAPS_CHAT) && (offset < buflen)) {
185 memcpy(capblock+offset, aim_caps[3], sizeof(aim_caps[3]));
186 offset += sizeof(aim_caps[3]);
188 if ((caps & AIM_CAPS_GETFILE) && (offset < buflen)) {
189 memcpy(capblock+offset, aim_caps[4], sizeof(aim_caps[4]));
190 offset += sizeof(aim_caps[4]);
192 if ((caps & AIM_CAPS_SENDFILE) && (offset < buflen)) {
193 memcpy(capblock+offset, aim_caps[5], sizeof(aim_caps[5]));
194 offset += sizeof(aim_caps[5]);
196 if ((caps & AIM_CAPS_GAMES) && (offset < buflen)) {
197 memcpy(capblock+offset, aim_caps[6], sizeof(aim_caps[6]));
198 offset += sizeof(aim_caps[6]);
200 if ((caps & AIM_CAPS_SAVESTOCKS) && (offset < buflen)) {
201 memcpy(capblock+offset, aim_caps[7], sizeof(aim_caps[7]));
202 offset += sizeof(aim_caps[7]);
209 * AIM is fairly regular about providing user info. This
210 * is a generic routine to extract it in its standard form.
212 faim_internal int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinfo)
222 if (!buf || !outinfo)
225 /* Clear out old data first */
226 memset(outinfo, 0x00, sizeof(struct aim_userinfo_s));
229 * Screen name. Stored as an unterminated string prepended
230 * with an unsigned byte containing its length.
232 if (buf[i] < MAXSNLEN) {
233 memcpy(outinfo->sn, &(buf[i+1]), buf[i]);
234 outinfo->sn[(int)buf[i]] = '\0';
236 memcpy(outinfo->sn, &(buf[i+1]), MAXSNLEN-1);
237 outinfo->sn[MAXSNLEN] = '\0';
242 * Warning Level. Stored as an unsigned short.
244 outinfo->warnlevel = aimutil_get16(&buf[i]);
248 * TLV Count. Unsigned short representing the number of
249 * Type-Length-Value triples that follow.
251 tlvcnt = aimutil_get16(&buf[i]);
255 * Parse out the Type-Length-Value triples as they're found.
257 while (curtlv < tlvcnt) {
259 curtype = aimutil_get16(&buf[i]);
262 * Type = 0x0000: Invalid
264 * AOL has been trying to throw these in just to break us.
265 * They're real nice guys over there at AOL.
267 * Just skip the two zero bytes and continue on. (This doesn't
268 * count towards tlvcnt!)
276 * Type = 0x0001: User flags
278 * Specified as any of the following bitwise ORed together:
279 * 0x0001 Trial (user less than 60days)
280 * 0x0002 Unknown bit 2
281 * 0x0004 AOL Main Service user
282 * 0x0008 Unknown bit 4
283 * 0x0010 Free (AIM) user
286 * In some odd cases, we can end up with more
287 * than one of these. We only want the first,
288 * as the others may not be something we want.
292 if (tlv1) /* use only the first */
294 outinfo->flags = aimutil_get16(&buf[i+4]);
299 * Type = 0x0002: Member-Since date.
301 * The time/date that the user originally
302 * registered for the service, stored in
306 outinfo->membersince = aimutil_get32(&buf[i+4]);
310 * Type = 0x0003: On-Since date.
312 * The time/date that the user started
313 * their current session, stored in time_t
317 outinfo->onlinesince = aimutil_get32(&buf[i+4]);
321 * Type = 0x0004: Idle time.
323 * Number of seconds since the user
324 * actively used the service.
327 outinfo->idletime = aimutil_get16(&buf[i+4]);
331 * Type = 0x0006: ICQ Online Status
333 * ICQ's Away/DND/etc "enriched" status
334 * Some decoding of values done by Scott <darkagl@pcnet.com>
337 outinfo->icqinfo.status = aimutil_get16(buf+i+2+2+2);
344 * ICQ User IP Address.
345 * Ahh, the joy of ICQ security.
348 outinfo->icqinfo.ipaddr = aimutil_get32(&buf[i+4]);
353 * random crap containing the IP address,
354 * apparently a port number, and some Other Stuff.
358 memcpy(outinfo->icqinfo.crap, &buf[i+4], 0x25);
364 * Capability information. Not real sure of
365 * actual decoding. See comment on aim_bos_setprofile()
366 * in aim_misc.c about the capability block, its the same.
372 len = aimutil_get16(buf+i+2);
376 outinfo->capabilities = aim_getcap(buf+i+4, len);
383 * Unknown. Always of zero length, and always only
393 * Type = 0x000f: Session Length. (AIM)
394 * Type = 0x0010: Session Length. (AOL)
396 * The duration, in seconds, of the user's
399 * Which TLV type this comes in depends
400 * on the service the user is using (AIM or AOL).
405 outinfo->sessionlen = aimutil_get32(&buf[i+4]);
409 * Reaching here indicates that either AOL has
410 * added yet another TLV for us to deal with,
411 * or the parsing has gone Terribly Wrong.
413 * Either way, inform the owner and attempt
419 int len,z = 0, y = 0, x = 0;
421 printf("faim: userinfo: **warning: unexpected TLV:\n");
422 printf("faim: userinfo: sn =%s\n", outinfo->sn);
423 printf("faim: userinfo: curtlv=0x%04x\n", curtlv);
424 printf("faim: userinfo: type =0x%04x\n",aimutil_get16(&buf[i]));
425 printf("faim: userinfo: length=0x%04x\n", len = aimutil_get16(&buf[i+2]));
426 printf("faim: userinfo: data: \n");
429 x = sprintf(tmpstr, "faim: userinfo: ");
430 for (y = 0; y < 8; y++)
434 sprintf(tmpstr+x, "%02x ", buf[i+4+z]);
441 printf("%s\n", tmpstr);
447 * No matter what, TLV triplets should always look like this:
451 * u_char data[length];
455 i += (2 + 2 + aimutil_get16(&buf[i+2]));
464 * Oncoming Buddy notifications contain a subset of the
465 * user information structure. Its close enough to run
466 * through aim_extractuserinfo() however.
469 faim_internal int aim_parse_oncoming_middle(struct aim_session_t *sess,
470 struct command_rx_struct *command)
472 struct aim_userinfo_s userinfo;
474 rxcallback_t userfunc=NULL;
477 i += aim_extractuserinfo(command->data+i, &userinfo);
479 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING);
481 i = userfunc(sess, command, &userinfo);
487 * Offgoing Buddy notifications contain no useful
488 * information other than the name it applies to.
491 faim_internal int aim_parse_offgoing_middle(struct aim_session_t *sess,
492 struct command_rx_struct *command)
496 rxcallback_t userfunc=NULL;
498 strncpy(sn, (char *)command->data+11, (int)command->data[10]);
499 sn[(int)command->data[10]] = '\0';
501 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING);
503 i = userfunc(sess, command, sn);
509 * This parses the user info stuff out all nice and pretty then calls
510 * the higher-level callback (in the user app).
513 faim_internal int aim_parse_userinfo_middle(struct aim_session_t *sess,
514 struct command_rx_struct *command)
516 struct aim_userinfo_s userinfo;
517 char *text_encoding = NULL;
520 rxcallback_t userfunc=NULL;
521 struct aim_tlvlist_t *tlvlist;
522 struct aim_snac_t *origsnac = NULL;
524 struct aim_priv_inforeq *inforeq;
526 snacid = aimutil_get32(&command->data[6]);
527 origsnac = aim_remsnac(sess, snacid);
529 if (!origsnac || !origsnac->data) {
530 printf("faim: parse_userinfo_middle: major problem: no snac stored!\n");
534 inforeq = (struct aim_priv_inforeq *)origsnac->data;
536 switch (inforeq->infotype) {
537 case AIM_GETINFO_GENERALINFO:
538 case AIM_GETINFO_AWAYMESSAGE:
542 * extractuserinfo will give us the basic metaTLV information
544 i += aim_extractuserinfo(command->data+i, &userinfo);
547 * However, in this command, there's usually more TLVs following...
549 tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
552 * Depending on what informational text was requested, different
553 * TLVs will appear here.
555 * Profile will be 1 and 2, away message will be 3 and 4.
557 if (aim_gettlv(tlvlist, 0x0001, 1)) {
558 text_encoding = aim_gettlv_str(tlvlist, 0x0001, 1);
559 text = aim_gettlv_str(tlvlist, 0x0002, 1);
560 } else if (aim_gettlv(tlvlist, 0x0003, 1)) {
561 text_encoding = aim_gettlv_str(tlvlist, 0x0003, 1);
562 text = aim_gettlv_str(tlvlist, 0x0004, 1);
565 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO);
577 aim_freetlvchain(&tlvlist);
580 printf("faim: parse_userinfo_middle: unknown infotype in request! (0x%04x)\n", inforeq->infotype);
586 free(origsnac->data);
594 * Inverse of aim_extractuserinfo()
596 faim_internal int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info)
598 int i = 0, numtlv = 0;
599 struct aim_tlvlist_t *tlvlist = NULL;
604 i += aimutil_put8(buf+i, strlen(info->sn));
605 i += aimutil_putstr(buf+i, info->sn, strlen(info->sn));
607 i += aimutil_put16(buf+i, info->warnlevel);
610 aim_addtlvtochain16(&tlvlist, 0x0001, info->flags);
613 aim_addtlvtochain32(&tlvlist, 0x0002, info->membersince);
616 aim_addtlvtochain32(&tlvlist, 0x0003, info->onlinesince);
619 aim_addtlvtochain16(&tlvlist, 0x0004, info->idletime);
622 #if ICQ_OSCAR_SUPPORT
623 if(atoi(info->sn) != 0) {
624 aim_addtlvtochain16(&tlvlist, 0x0006, info->icqinfo.status);
625 aim_addtlvtochain32(&tlvlist, 0x000a, info->icqinfo.ipaddr);
629 aim_addtlvtochain_caps(&tlvlist, 0x000d, info->capabilities);
632 aim_addtlvtochain32(&tlvlist, (unsigned short)((info->flags)&AIM_FLAG_AOL?0x0010:0x000f), info->sessionlen);
635 i += aimutil_put16(buf+i, numtlv); /* tlvcount */
636 i += aim_writetlvchain(buf+i, buflen-i, &tlvlist); /* tlvs */
637 aim_freetlvchain(&tlvlist);
642 faim_export int aim_sendbuddyoncoming(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_userinfo_s *info)
644 struct command_tx_struct *tx;
647 if (!sess || !conn || !info)
650 if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152)))
655 i += aimutil_put16(tx->data+i, 0x0003);
656 i += aimutil_put16(tx->data+i, 0x000b);
657 i += aimutil_put16(tx->data+i, 0x0000);
658 i += aimutil_put16(tx->data+i, 0x0000);
659 i += aimutil_put16(tx->data+i, 0x0000);
661 i += aim_putuserinfo(tx->data+i, tx->commandlen-i, info);
665 aim_tx_enqueue(sess, tx);
670 faim_export int aim_sendbuddyoffgoing(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn)
672 struct command_tx_struct *tx;
675 if (!sess || !conn || !sn)
678 if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+1+strlen(sn))))
683 i += aimutil_put16(tx->data+i, 0x0003);
684 i += aimutil_put16(tx->data+i, 0x000c);
685 i += aimutil_put16(tx->data+i, 0x0000);
686 i += aimutil_put16(tx->data+i, 0x0000);
687 i += aimutil_put16(tx->data+i, 0x0000);
689 i += aimutil_put8(tx->data+i, strlen(sn));
690 i += aimutil_putstr(tx->data+i, sn, strlen(sn));
693 aim_tx_enqueue(sess, tx);