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;
25 if (!sess || !conn || !sn)
28 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 12+1+strlen(sn))))
33 i = aim_putsnac(newpacket->data, 0x0002, 0x0005, 0x0000, sess->snac_nextid);
35 i += aimutil_put16(newpacket->data+i, infotype);
36 i += aimutil_put8(newpacket->data+i, strlen(sn));
37 i += aimutil_putstr(newpacket->data+i, sn, strlen(sn));
40 aim_tx_enqueue(sess, newpacket);
43 struct aim_snac_t snac;
45 snac.id = sess->snac_nextid;
50 snac.data = malloc(sizeof(struct aim_priv_inforeq));
51 strcpy(((struct aim_priv_inforeq *)snac.data)->sn, sn);
52 ((struct aim_priv_inforeq *)snac.data)->infotype = infotype;
54 aim_newsnac(sess, &snac);
57 return (sess->snac_nextid++);
60 faim_internal int aim_parse_locateerr(struct aim_session_t *sess,
61 struct command_rx_struct *command)
63 u_long snacid = 0x000000000;
64 struct aim_snac_t *snac = NULL;
66 rxcallback_t userfunc = NULL;
68 unsigned short reason = 0;
71 * Get SNAC from packet and look it up
72 * the list of unrepliedto/outstanding
76 snacid = aimutil_get32(command->data+6);
77 snac = aim_remsnac(sess, snacid);
80 printf("faim: locerr: got an locate-failed error on an unknown SNAC ID! (%08lx)\n", snacid);
85 reason = aimutil_get16(command->data+10);
90 userfunc = aim_callhandler(command->conn, 0x0002, 0x0001);
92 ret = userfunc(sess, command, dest, reason);
107 u_char aim_caps[6][16] = {
110 {0x09, 0x46, 0x13, 0x46, 0x4c, 0x7f, 0x11, 0xd1,
111 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
114 {0x09, 0x46, 0x13, 0x41, 0x4c, 0x7f, 0x11, 0xd1,
115 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
118 {0x09, 0x46, 0x13, 0x45, 0x4c, 0x7f, 0x11, 0xd1,
119 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
122 {0x74, 0x8f, 0x24, 0x20, 0x62, 0x87, 0x11, 0xd1,
123 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
126 {0x09, 0x46, 0x13, 0x48, 0x4c, 0x7f, 0x11, 0xd1,
127 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
130 {0x09, 0x46, 0x13, 0x43, 0x4c, 0x7f, 0x11, 0xd1,
131 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}
134 faim_internal unsigned short aim_getcap(unsigned char *capblock, int buflen)
140 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; break;
145 case 1: ret |= AIM_CAPS_VOICE; break;
146 case 2: ret |= AIM_CAPS_IMIMAGE; break;
147 case 3: ret |= AIM_CAPS_CHAT; break;
148 case 4: ret |= AIM_CAPS_GETFILE; break;
149 case 5: ret |= AIM_CAPS_SENDFILE; break;
150 default: ret |= 0xff00; break;
159 faim_internal int aim_putcap(unsigned char *capblock, int buflen, u_short caps)
166 if ((caps & AIM_CAPS_BUDDYICON) && (offset < buflen)) {
167 memcpy(capblock+offset, aim_caps[0], sizeof(aim_caps[0]));
168 offset += sizeof(aim_caps[1]);
170 if ((caps & AIM_CAPS_VOICE) && (offset < buflen)) {
171 memcpy(capblock+offset, aim_caps[1], sizeof(aim_caps[1]));
172 offset += sizeof(aim_caps[1]);
174 if ((caps & AIM_CAPS_IMIMAGE) && (offset < buflen)) {
175 memcpy(capblock+offset, aim_caps[2], sizeof(aim_caps[2]));
176 offset += sizeof(aim_caps[2]);
178 if ((caps & AIM_CAPS_CHAT) && (offset < buflen)) {
179 memcpy(capblock+offset, aim_caps[3], sizeof(aim_caps[3]));
180 offset += sizeof(aim_caps[3]);
182 if ((caps & AIM_CAPS_GETFILE) && (offset < buflen)) {
183 memcpy(capblock+offset, aim_caps[4], sizeof(aim_caps[4]));
184 offset += sizeof(aim_caps[4]);
186 if ((caps & AIM_CAPS_SENDFILE) && (offset < buflen)) {
187 memcpy(capblock+offset, aim_caps[5], sizeof(aim_caps[5]));
188 offset += sizeof(aim_caps[5]);
195 * AIM is fairly regular about providing user info. This
196 * is a generic routine to extract it in its standard form.
198 faim_internal int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinfo)
208 if (!buf || !outinfo)
211 /* Clear out old data first */
212 memset(outinfo, 0x00, sizeof(struct aim_userinfo_s));
215 * Screen name. Stored as an unterminated string prepended
216 * with an unsigned byte containing its length.
218 if (buf[i] < MAXSNLEN) {
219 memcpy(outinfo->sn, &(buf[i+1]), buf[i]);
220 outinfo->sn[(int)buf[i]] = '\0';
222 memcpy(outinfo->sn, &(buf[i+1]), MAXSNLEN-1);
223 outinfo->sn[MAXSNLEN] = '\0';
228 * Warning Level. Stored as an unsigned short.
230 outinfo->warnlevel = aimutil_get16(&buf[i]);
234 * TLV Count. Unsigned short representing the number of
235 * Type-Length-Value triples that follow.
237 tlvcnt = aimutil_get16(&buf[i]);
241 * Parse out the Type-Length-Value triples as they're found.
243 while (curtlv < tlvcnt) {
245 curtype = aimutil_get16(&buf[i]);
248 * Type = 0x0000: Invalid
250 * AOL has been trying to throw these in just to break us.
251 * They're real nice guys over there at AOL.
253 * Just skip the two zero bytes and continue on. (This doesn't
254 * count towards tlvcnt!)
262 * Type = 0x0001: User flags
264 * Specified as any of the following bitwise ORed together:
265 * 0x0001 Trial (user less than 60days)
266 * 0x0002 Unknown bit 2
267 * 0x0004 AOL Main Service user
268 * 0x0008 Unknown bit 4
269 * 0x0010 Free (AIM) user
272 * In some odd cases, we can end up with more
273 * than one of these. We only want the first,
274 * as the others may not be something we want.
278 if (tlv1) /* use only the first */
280 outinfo->flags = aimutil_get16(&buf[i+4]);
285 * Type = 0x0002: Member-Since date.
287 * The time/date that the user originally
288 * registered for the service, stored in
292 outinfo->membersince = aimutil_get32(&buf[i+4]);
296 * Type = 0x0003: On-Since date.
298 * The time/date that the user started
299 * their current session, stored in time_t
303 outinfo->onlinesince = aimutil_get32(&buf[i+4]);
307 * Type = 0x0004: Idle time.
309 * Number of seconds since the user
310 * actively used the service.
313 outinfo->idletime = aimutil_get16(&buf[i+4]);
317 * Type = 0x0006: ICQ Online Status
319 * ICQ's Away/DND/etc "enriched" status
320 * Some decoding of values done by Scott <darkagl@pcnet.com>
323 outinfo->icqinfo.status = aimutil_get16(buf+i+2+2+2);
330 * ICQ User IP Address.
331 * Ahh, the joy of ICQ security.
334 outinfo->icqinfo.ipaddr = aimutil_get32(&buf[i+4]);
339 * random crap containing the IP address,
340 * apparently a port number, and some Other Stuff.
344 memcpy(outinfo->icqinfo.crap, &buf[i+4], 0x25);
350 * Capability information. Not real sure of
351 * actual decoding. See comment on aim_bos_setprofile()
352 * in aim_misc.c about the capability block, its the same.
358 len = aimutil_get16(buf+i+2);
362 outinfo->capabilities = aim_getcap(buf+i+4, len);
369 * Unknown. Always of zero length, and always only
379 * Type = 0x000f: Session Length. (AIM)
380 * Type = 0x0010: Session Length. (AOL)
382 * The duration, in seconds, of the user's
385 * Which TLV type this comes in depends
386 * on the service the user is using (AIM or AOL).
391 outinfo->sessionlen = aimutil_get32(&buf[i+4]);
395 * Reaching here indicates that either AOL has
396 * added yet another TLV for us to deal with,
397 * or the parsing has gone Terribly Wrong.
399 * Either way, inform the owner and attempt
405 int len,z = 0, y = 0, x = 0;
407 printf("faim: userinfo: **warning: unexpected TLV:\n");
408 printf("faim: userinfo: sn =%s\n", outinfo->sn);
409 printf("faim: userinfo: curtlv=0x%04x\n", curtlv);
410 printf("faim: userinfo: type =0x%04x\n",aimutil_get16(&buf[i]));
411 printf("faim: userinfo: length=0x%04x\n", len = aimutil_get16(&buf[i+2]));
412 printf("faim: userinfo: data: \n");
415 x = sprintf(tmpstr, "faim: userinfo: ");
416 for (y = 0; y < 8; y++)
420 sprintf(tmpstr+x, "%02x ", buf[i+4+z]);
427 printf("%s\n", tmpstr);
433 * No matter what, TLV triplets should always look like this:
437 * u_char data[length];
441 i += (2 + 2 + aimutil_get16(&buf[i+2]));
450 * Oncoming Buddy notifications contain a subset of the
451 * user information structure. Its close enough to run
452 * through aim_extractuserinfo() however.
455 faim_internal int aim_parse_oncoming_middle(struct aim_session_t *sess,
456 struct command_rx_struct *command)
458 struct aim_userinfo_s userinfo;
460 rxcallback_t userfunc=NULL;
463 i += aim_extractuserinfo(command->data+i, &userinfo);
465 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING);
467 i = userfunc(sess, command, &userinfo);
473 * Offgoing Buddy notifications contain no useful
474 * information other than the name it applies to.
477 faim_internal int aim_parse_offgoing_middle(struct aim_session_t *sess,
478 struct command_rx_struct *command)
482 rxcallback_t userfunc=NULL;
484 strncpy(sn, (char *)command->data+11, (int)command->data[10]);
485 sn[(int)command->data[10]] = '\0';
487 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING);
489 i = userfunc(sess, command, sn);
495 * This parses the user info stuff out all nice and pretty then calls
496 * the higher-level callback (in the user app).
499 faim_internal int aim_parse_userinfo_middle(struct aim_session_t *sess,
500 struct command_rx_struct *command)
502 struct aim_userinfo_s userinfo;
503 char *text_encoding = NULL;
506 rxcallback_t userfunc=NULL;
507 struct aim_tlvlist_t *tlvlist;
508 struct aim_snac_t *origsnac = NULL;
510 struct aim_priv_inforeq *inforeq;
512 snacid = aimutil_get32(&command->data[6]);
513 origsnac = aim_remsnac(sess, snacid);
515 if (!origsnac || !origsnac->data) {
516 printf("faim: parse_userinfo_middle: major problem: no snac stored!\n");
520 inforeq = (struct aim_priv_inforeq *)origsnac->data;
522 switch (inforeq->infotype) {
523 case AIM_GETINFO_GENERALINFO:
524 case AIM_GETINFO_AWAYMESSAGE:
528 * extractuserinfo will give us the basic metaTLV information
530 i += aim_extractuserinfo(command->data+i, &userinfo);
533 * However, in this command, there's usually more TLVs following...
535 tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
538 * Depending on what informational text was requested, different
539 * TLVs will appear here.
541 * Profile will be 1 and 2, away message will be 3 and 4.
543 if (aim_gettlv(tlvlist, 0x0001, 1)) {
544 text_encoding = aim_gettlv_str(tlvlist, 0x0001, 1);
545 text = aim_gettlv_str(tlvlist, 0x0002, 1);
546 } else if (aim_gettlv(tlvlist, 0x0003, 1)) {
547 text_encoding = aim_gettlv_str(tlvlist, 0x0003, 1);
548 text = aim_gettlv_str(tlvlist, 0x0004, 1);
551 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO);
563 aim_freetlvchain(&tlvlist);
566 printf("faim: parse_userinfo_middle: unknown infotype in request! (0x%04x)\n", inforeq->infotype);
572 free(origsnac->data);
580 * Inverse of aim_extractuserinfo()
582 faim_internal int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info)
584 int i = 0, numtlv = 0;
585 struct aim_tlvlist_t *tlvlist = NULL;
590 i += aimutil_put8(buf+i, strlen(info->sn));
591 i += aimutil_putstr(buf+i, info->sn, strlen(info->sn));
593 i += aimutil_put16(buf+i, info->warnlevel);
596 aim_addtlvtochain16(&tlvlist, 0x0001, info->flags);
599 aim_addtlvtochain32(&tlvlist, 0x0002, info->membersince);
602 aim_addtlvtochain32(&tlvlist, 0x0003, info->onlinesince);
605 aim_addtlvtochain16(&tlvlist, 0x0004, info->idletime);
608 #if ICQ_OSCAR_SUPPORT
609 if(atoi(info->sn) != 0) {
610 aim_addtlvtochain16(&tlvlist, 0x0006, info->icqinfo.status);
611 aim_addtlvtochain32(&tlvlist, 0x000a, info->icqinfo.ipaddr);
615 aim_addtlvtochain_caps(&tlvlist, 0x000d, info->capabilities);
618 aim_addtlvtochain32(&tlvlist, (unsigned short)((info->flags)&AIM_FLAG_AOL?0x0010:0x000f), info->sessionlen);
621 i += aimutil_put16(buf+i, numtlv); /* tlvcount */
622 i += aim_writetlvchain(buf+i, buflen-i, &tlvlist); /* tlvs */
623 aim_freetlvchain(&tlvlist);
628 faim_export int aim_sendbuddyoncoming(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_userinfo_s *info)
630 struct command_tx_struct *tx;
633 if (!sess || !conn || !info)
636 if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152)))
641 i += aimutil_put16(tx->data+i, 0x0003);
642 i += aimutil_put16(tx->data+i, 0x000b);
643 i += aimutil_put16(tx->data+i, 0x0000);
644 i += aimutil_put16(tx->data+i, 0x0000);
645 i += aimutil_put16(tx->data+i, 0x0000);
647 i += aim_putuserinfo(tx->data+i, tx->commandlen-i, info);
651 aim_tx_enqueue(sess, tx);
656 faim_export int aim_sendbuddyoffgoing(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn)
658 struct command_tx_struct *tx;
661 if (!sess || !conn || !sn)
664 if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+1+strlen(sn))))
669 i += aimutil_put16(tx->data+i, 0x0003);
670 i += aimutil_put16(tx->data+i, 0x000c);
671 i += aimutil_put16(tx->data+i, 0x0000);
672 i += aimutil_put16(tx->data+i, 0x0000);
673 i += aimutil_put16(tx->data+i, 0x0000);
675 i += aimutil_put8(tx->data+i, strlen(sn));
676 i += aimutil_putstr(tx->data+i, sn, strlen(sn));
679 aim_tx_enqueue(sess, tx);