4 * The functions here are responsible for requesting and parsing information-
12 struct aim_priv_inforeq {
14 unsigned short infotype;
17 faim_export int 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 ((infotype != AIM_GETINFO_GENERALINFO) &&
30 (infotype != AIM_GETINFO_AWAYMESSAGE))
33 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 12+1+strlen(sn))))
38 i = aim_putsnac(newpacket->data, 0x0002, 0x0005, 0x0000, sess->snac_nextid);
40 i += aimutil_put16(newpacket->data+i, infotype);
41 i += aimutil_put8(newpacket->data+i, strlen(sn));
42 i += aimutil_putstr(newpacket->data+i, sn, strlen(sn));
45 aim_tx_enqueue(sess, newpacket);
47 strncpy(privdata.sn, sn, sizeof(privdata.sn));
48 privdata.infotype = infotype;
49 aim_cachesnac(sess, 0x0002, 0x0005, 0x0000, &privdata, sizeof(struct aim_priv_inforeq));
59 unsigned char data[16];
63 {0x09, 0x46, 0x13, 0x46, 0x4c, 0x7f, 0x11, 0xd1,
64 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
67 {0x09, 0x46, 0x13, 0x41, 0x4c, 0x7f, 0x11, 0xd1,
68 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
71 {0x09, 0x46, 0x13, 0x45, 0x4c, 0x7f, 0x11, 0xd1,
72 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
75 {0x74, 0x8f, 0x24, 0x20, 0x62, 0x87, 0x11, 0xd1,
76 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
79 {0x09, 0x46, 0x13, 0x48, 0x4c, 0x7f, 0x11, 0xd1,
80 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
83 {0x09, 0x46, 0x13, 0x43, 0x4c, 0x7f, 0x11, 0xd1,
84 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
87 {0x09, 0x46, 0x13, 0x47, 0x4c, 0x7f, 0x11, 0xd1,
88 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
91 * Indeed, there are two of these. The former appears
92 * to be correct, but in some versions of winaim, the
93 * second one is set. Either they forgot to fix endianness,
94 * or they made a typo. It really doesn't matter which.
97 {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1,
98 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
100 {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1,
101 0x22, 0x82, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
103 {AIM_CAPS_SENDBUDDYLIST,
104 {0x09, 0x46, 0x13, 0x4b, 0x4c, 0x7f, 0x11, 0xd1,
105 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
110 faim_internal unsigned short aim_getcap(struct aim_session_t *sess, unsigned char *capblock, int buflen)
112 unsigned short flags;
117 for (offset = 0, flags = 0; offset < buflen; offset += 0x0010) {
119 for (i = 0, identified = 0; !(aim_caps[i].flag & AIM_CAPS_LAST); i++) {
121 if (memcmp(&aim_caps[i].data, capblock+offset, 0x10) == 0) {
122 flags |= aim_caps[i].flag;
124 break; /* should only match once... */
130 faimdprintf(sess, 0, "unknown capability!\n");
137 faim_internal int aim_putcap(unsigned char *capblock, int buflen, unsigned short caps)
144 for (i = 0, offset = 0;
145 !(aim_caps[i].flag & AIM_CAPS_LAST) && (offset < buflen); i++) {
147 if (caps & aim_caps[i].flag) {
148 memcpy(capblock+offset, aim_caps[i].data, 16);
158 * AIM is fairly regular about providing user info. This
159 * is a generic routine to extract it in its standard form.
161 faim_internal int aim_extractuserinfo(struct aim_session_t *sess, unsigned char *buf, struct aim_userinfo_s *outinfo)
171 if (!buf || !outinfo)
174 /* Clear out old data first */
175 memset(outinfo, 0x00, sizeof(struct aim_userinfo_s));
178 * Screen name. Stored as an unterminated string prepended
179 * with an unsigned byte containing its length.
181 if (buf[i] < MAXSNLEN) {
182 memcpy(outinfo->sn, &(buf[i+1]), buf[i]);
183 outinfo->sn[(int)buf[i]] = '\0';
185 memcpy(outinfo->sn, &(buf[i+1]), MAXSNLEN-1);
186 outinfo->sn[MAXSNLEN] = '\0';
191 * Warning Level. Stored as an unsigned short.
193 outinfo->warnlevel = aimutil_get16(&buf[i]);
197 * TLV Count. Unsigned short representing the number of
198 * Type-Length-Value triples that follow.
200 tlvcnt = aimutil_get16(&buf[i]);
204 * Parse out the Type-Length-Value triples as they're found.
206 while (curtlv < tlvcnt) {
208 curtype = aimutil_get16(&buf[i]);
211 * Type = 0x0000: Invalid
213 * AOL has been trying to throw these in just to break us.
214 * They're real nice guys over there at AOL.
216 * Just skip the two zero bytes and continue on. (This doesn't
217 * count towards tlvcnt!)
225 * Type = 0x0001: User flags
227 * Specified as any of the following bitwise ORed together:
228 * 0x0001 Trial (user less than 60days)
229 * 0x0002 Unknown bit 2
230 * 0x0004 AOL Main Service user
231 * 0x0008 Unknown bit 4
232 * 0x0010 Free (AIM) user
235 * In some odd cases, we can end up with more
236 * than one of these. We only want the first,
237 * as the others may not be something we want.
241 if (tlv1) /* use only the first */
243 outinfo->flags = aimutil_get16(&buf[i+4]);
248 * Type = 0x0002: Member-Since date.
250 * The time/date that the user originally
251 * registered for the service, stored in
255 outinfo->membersince = aimutil_get32(&buf[i+4]);
259 * Type = 0x0003: On-Since date.
261 * The time/date that the user started
262 * their current session, stored in time_t
266 outinfo->onlinesince = aimutil_get32(&buf[i+4]);
270 * Type = 0x0004: Idle time.
272 * Number of seconds since the user
273 * actively used the service.
276 outinfo->idletime = aimutil_get16(&buf[i+4]);
280 * Type = 0x0006: ICQ Online Status
282 * ICQ's Away/DND/etc "enriched" status
283 * Some decoding of values done by Scott <darkagl@pcnet.com>
286 outinfo->icqinfo.status = aimutil_get16(buf+i+2+2+2);
293 * ICQ User IP Address.
294 * Ahh, the joy of ICQ security.
297 outinfo->icqinfo.ipaddr = aimutil_get32(&buf[i+4]);
302 * random crap containing the IP address,
303 * apparently a port number, and some Other Stuff.
307 memcpy(outinfo->icqinfo.crap, &buf[i+4], 0x25);
313 * Capability information. Not real sure of
314 * actual decoding. See comment on aim_bos_setprofile()
315 * in aim_misc.c about the capability block, its the same.
321 len = aimutil_get16(buf+i+2);
325 outinfo->capabilities = aim_getcap(sess, buf+i+4, len);
332 * Unknown. Always of zero length, and always only
342 * Type = 0x000f: Session Length. (AIM)
343 * Type = 0x0010: Session Length. (AOL)
345 * The duration, in seconds, of the user's
348 * Which TLV type this comes in depends
349 * on the service the user is using (AIM or AOL).
354 outinfo->sessionlen = aimutil_get32(&buf[i+4]);
358 * Reaching here indicates that either AOL has
359 * added yet another TLV for us to deal with,
360 * or the parsing has gone Terribly Wrong.
362 * Either way, inform the owner and attempt
368 int len,z = 0, y = 0, x = 0;
371 faimdprintf(sess, 0, "userinfo: **warning: unexpected TLV:\n");
372 faimdprintf(sess, 0, "userinfo: sn =%s\n", outinfo->sn);
373 faimdprintf(sess, 0, "userinfo: curtlv=0x%04x\n", curtlv);
374 faimdprintf(sess, 0, "userinfo: type =0x%04x\n",aimutil_get16(&buf[i]));
375 faimdprintf(sess, 0, "userinfo: length=0x%04x\n", len = aimutil_get16(&buf[i+2]));
376 faimdprintf(sess, 0, "userinfo: data: \n");
379 x = snprintf(tmpstr, sizeof(tmpstr), "userinfo: ");
380 for (y = 0; y < 8; y++)
384 snprintf(tmpstr+x, sizeof(tmpstr)-x, "%02x ", buf[i+4+z]);
391 faimdprintf(sess, 0, "%s\n", tmpstr);
397 * No matter what, TLV triplets should always look like this:
401 * u_char data[length];
405 i += (2 + 2 + aimutil_get16(&buf[i+2]));
414 * Inverse of aim_extractuserinfo()
416 faim_internal int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info)
418 int i = 0, numtlv = 0;
419 struct aim_tlvlist_t *tlvlist = NULL;
424 i += aimutil_put8(buf+i, strlen(info->sn));
425 i += aimutil_putstr(buf+i, info->sn, strlen(info->sn));
427 i += aimutil_put16(buf+i, info->warnlevel);
430 aim_addtlvtochain16(&tlvlist, 0x0001, info->flags);
433 aim_addtlvtochain32(&tlvlist, 0x0002, info->membersince);
436 aim_addtlvtochain32(&tlvlist, 0x0003, info->onlinesince);
439 aim_addtlvtochain16(&tlvlist, 0x0004, info->idletime);
442 #if ICQ_OSCAR_SUPPORT
443 if(atoi(info->sn) != 0) {
444 aim_addtlvtochain16(&tlvlist, 0x0006, info->icqinfo.status);
445 aim_addtlvtochain32(&tlvlist, 0x000a, info->icqinfo.ipaddr);
449 aim_addtlvtochain_caps(&tlvlist, 0x000d, info->capabilities);
452 aim_addtlvtochain32(&tlvlist, (unsigned short)((info->flags)&AIM_FLAG_AOL?0x0010:0x000f), info->sessionlen);
455 i += aimutil_put16(buf+i, numtlv); /* tlvcount */
456 i += aim_writetlvchain(buf+i, buflen-i, &tlvlist); /* tlvs */
457 aim_freetlvchain(&tlvlist);
462 faim_export int aim_sendbuddyoncoming(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_userinfo_s *info)
464 struct command_tx_struct *tx;
467 if (!sess || !conn || !info)
470 if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152)))
475 i += aimutil_put16(tx->data+i, 0x0003);
476 i += aimutil_put16(tx->data+i, 0x000b);
477 i += aimutil_put16(tx->data+i, 0x0000);
478 i += aimutil_put16(tx->data+i, 0x0000);
479 i += aimutil_put16(tx->data+i, 0x0000);
481 i += aim_putuserinfo(tx->data+i, tx->commandlen-i, info);
485 aim_tx_enqueue(sess, tx);
490 faim_export int aim_sendbuddyoffgoing(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn)
492 struct command_tx_struct *tx;
495 if (!sess || !conn || !sn)
498 if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn))))
503 i += aimutil_put16(tx->data+i, 0x0003);
504 i += aimutil_put16(tx->data+i, 0x000c);
505 i += aimutil_put16(tx->data+i, 0x0000);
506 i += aimutil_put16(tx->data+i, 0x0000);
507 i += aimutil_put16(tx->data+i, 0x0000);
509 i += aimutil_put8(tx->data+i, strlen(sn));
510 i += aimutil_putstr(tx->data+i, sn, strlen(sn));
513 aim_tx_enqueue(sess, tx);
518 faim_export int aim_0002_000b(struct aim_session_t *sess, struct aim_conn_t *conn, const char *sn)
520 struct command_tx_struct *tx;
523 if (!sess || !conn || !sn)
526 if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn))))
531 i = aim_putsnac(tx->data, 0x0002, 0x000b, 0x0000, sess->snac_nextid);
532 i += aimutil_put8(tx->data+i, strlen(sn));
533 i += aimutil_putstr(tx->data+i, sn, strlen(sn));
537 aim_tx_enqueue(sess, tx);
544 * t(0001) - short containing max profile length (value = 1024)
545 * t(0002) - short - unknown (value = 16) [max MIME type length?]
546 * t(0003) - short - unknown (value = 7)
548 static int rights(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
550 struct aim_tlvlist_t *tlvlist;
551 aim_rxcallback_t userfunc;
553 unsigned short maxsiglen = 0;
555 tlvlist = aim_readtlvchain(data, datalen);
557 if (aim_gettlv(tlvlist, 0x0001, 1))
558 maxsiglen = aim_gettlv16(tlvlist, 0x0001, 1);
560 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
561 ret = userfunc(sess, rx, maxsiglen);
563 aim_freetlvchain(&tlvlist);
568 static int userinfo(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
570 struct aim_userinfo_s userinfo;
571 char *text_encoding = NULL;
574 aim_rxcallback_t userfunc;
575 struct aim_tlvlist_t *tlvlist;
576 struct aim_snac_t *origsnac = NULL;
577 struct aim_priv_inforeq *inforeq;
580 origsnac = aim_remsnac(sess, snac->id);
582 if (!origsnac || !origsnac->data) {
583 faimdprintf(sess, 0, "parse_userinfo_middle: major problem: no snac stored!\n");
587 inforeq = (struct aim_priv_inforeq *)origsnac->data;
589 if ((inforeq->infotype != AIM_GETINFO_GENERALINFO) &&
590 (inforeq->infotype != AIM_GETINFO_AWAYMESSAGE)) {
591 faimdprintf(sess, 0, "parse_userinfo_middle: unknown infotype in request! (0x%04x)\n", inforeq->infotype);
595 i = aim_extractuserinfo(sess, data, &userinfo);
597 tlvlist = aim_readtlvchain(data+i, datalen-i);
600 * Depending on what informational text was requested, different
601 * TLVs will appear here.
603 * Profile will be 1 and 2, away message will be 3 and 4.
605 if (aim_gettlv(tlvlist, 0x0001, 1)) {
606 text_encoding = aim_gettlv_str(tlvlist, 0x0001, 1);
607 text = aim_gettlv_str(tlvlist, 0x0002, 1);
608 } else if (aim_gettlv(tlvlist, 0x0003, 1)) {
609 text_encoding = aim_gettlv_str(tlvlist, 0x0003, 1);
610 text = aim_gettlv_str(tlvlist, 0x0004, 1);
613 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
614 ret = userfunc(sess, rx, &userinfo, text_encoding, text, inforeq->infotype);
619 aim_freetlvchain(&tlvlist);
623 free(origsnac->data);
630 static int snachandler(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
633 if (snac->subtype == 0x0003)
634 return rights(sess, mod, rx, snac, data, datalen);
635 else if (snac->subtype == 0x0006)
636 return userinfo(sess, mod, rx, snac, data, datalen);
641 faim_internal int locate_modfirst(struct aim_session_t *sess, aim_module_t *mod)
644 mod->family = 0x0002;
645 mod->version = 0x0000;
647 strncpy(mod->name, "locate", sizeof(mod->name));
648 mod->snachandler = snachandler;