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));
57 u_char aim_caps[8][16] = {
60 {0x09, 0x46, 0x13, 0x46, 0x4c, 0x7f, 0x11, 0xd1,
61 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
64 {0x09, 0x46, 0x13, 0x41, 0x4c, 0x7f, 0x11, 0xd1,
65 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
68 {0x09, 0x46, 0x13, 0x45, 0x4c, 0x7f, 0x11, 0xd1,
69 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
72 {0x74, 0x8f, 0x24, 0x20, 0x62, 0x87, 0x11, 0xd1,
73 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
76 {0x09, 0x46, 0x13, 0x48, 0x4c, 0x7f, 0x11, 0xd1,
77 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
80 {0x09, 0x46, 0x13, 0x43, 0x4c, 0x7f, 0x11, 0xd1,
81 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
83 /* Saves stock portfolios */
84 {0x09, 0x46, 0x13, 0x47, 0x4c, 0x7f, 0x11, 0xd1,
85 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
88 {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1,
89 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
92 faim_internal unsigned short aim_getcap(struct aim_session_t *sess, unsigned char *capblock, int buflen)
99 while (offset < buflen) {
101 for(y=0; y < (sizeof(aim_caps)/0x10); y++) {
102 if (memcmp(&aim_caps[y], capblock+offset, 0x10) == 0) {
104 case 0: ret |= AIM_CAPS_BUDDYICON; identified++; break;
105 case 1: ret |= AIM_CAPS_VOICE; identified++; break;
106 case 2: ret |= AIM_CAPS_IMIMAGE; identified++; break;
107 case 3: ret |= AIM_CAPS_CHAT; identified++; break;
108 case 4: ret |= AIM_CAPS_GETFILE; identified++; break;
109 case 5: ret |= AIM_CAPS_SENDFILE; identified++; break;
110 case 6: ret |= AIM_CAPS_GAMES; identified++; break;
111 case 7: ret |= AIM_CAPS_SAVESTOCKS; identified++; break;
116 faimdprintf(sess, 0, "unknown capability!\n");
125 faim_internal int aim_putcap(unsigned char *capblock, int buflen, u_short caps)
132 if ((caps & AIM_CAPS_BUDDYICON) && (offset < buflen)) {
133 memcpy(capblock+offset, aim_caps[0], sizeof(aim_caps[0]));
134 offset += sizeof(aim_caps[1]);
136 if ((caps & AIM_CAPS_VOICE) && (offset < buflen)) {
137 memcpy(capblock+offset, aim_caps[1], sizeof(aim_caps[1]));
138 offset += sizeof(aim_caps[1]);
140 if ((caps & AIM_CAPS_IMIMAGE) && (offset < buflen)) {
141 memcpy(capblock+offset, aim_caps[2], sizeof(aim_caps[2]));
142 offset += sizeof(aim_caps[2]);
144 if ((caps & AIM_CAPS_CHAT) && (offset < buflen)) {
145 memcpy(capblock+offset, aim_caps[3], sizeof(aim_caps[3]));
146 offset += sizeof(aim_caps[3]);
148 if ((caps & AIM_CAPS_GETFILE) && (offset < buflen)) {
149 memcpy(capblock+offset, aim_caps[4], sizeof(aim_caps[4]));
150 offset += sizeof(aim_caps[4]);
152 if ((caps & AIM_CAPS_SENDFILE) && (offset < buflen)) {
153 memcpy(capblock+offset, aim_caps[5], sizeof(aim_caps[5]));
154 offset += sizeof(aim_caps[5]);
156 if ((caps & AIM_CAPS_GAMES) && (offset < buflen)) {
157 memcpy(capblock+offset, aim_caps[6], sizeof(aim_caps[6]));
158 offset += sizeof(aim_caps[6]);
160 if ((caps & AIM_CAPS_SAVESTOCKS) && (offset < buflen)) {
161 memcpy(capblock+offset, aim_caps[7], sizeof(aim_caps[7]));
162 offset += sizeof(aim_caps[7]);
169 * AIM is fairly regular about providing user info. This
170 * is a generic routine to extract it in its standard form.
172 faim_internal int aim_extractuserinfo(struct aim_session_t *sess, unsigned char *buf, struct aim_userinfo_s *outinfo)
182 if (!buf || !outinfo)
185 /* Clear out old data first */
186 memset(outinfo, 0x00, sizeof(struct aim_userinfo_s));
189 * Screen name. Stored as an unterminated string prepended
190 * with an unsigned byte containing its length.
192 if (buf[i] < MAXSNLEN) {
193 memcpy(outinfo->sn, &(buf[i+1]), buf[i]);
194 outinfo->sn[(int)buf[i]] = '\0';
196 memcpy(outinfo->sn, &(buf[i+1]), MAXSNLEN-1);
197 outinfo->sn[MAXSNLEN] = '\0';
202 * Warning Level. Stored as an unsigned short.
204 outinfo->warnlevel = aimutil_get16(&buf[i]);
208 * TLV Count. Unsigned short representing the number of
209 * Type-Length-Value triples that follow.
211 tlvcnt = aimutil_get16(&buf[i]);
215 * Parse out the Type-Length-Value triples as they're found.
217 while (curtlv < tlvcnt) {
219 curtype = aimutil_get16(&buf[i]);
222 * Type = 0x0000: Invalid
224 * AOL has been trying to throw these in just to break us.
225 * They're real nice guys over there at AOL.
227 * Just skip the two zero bytes and continue on. (This doesn't
228 * count towards tlvcnt!)
236 * Type = 0x0001: User flags
238 * Specified as any of the following bitwise ORed together:
239 * 0x0001 Trial (user less than 60days)
240 * 0x0002 Unknown bit 2
241 * 0x0004 AOL Main Service user
242 * 0x0008 Unknown bit 4
243 * 0x0010 Free (AIM) user
246 * In some odd cases, we can end up with more
247 * than one of these. We only want the first,
248 * as the others may not be something we want.
252 if (tlv1) /* use only the first */
254 outinfo->flags = aimutil_get16(&buf[i+4]);
259 * Type = 0x0002: Member-Since date.
261 * The time/date that the user originally
262 * registered for the service, stored in
266 outinfo->membersince = aimutil_get32(&buf[i+4]);
270 * Type = 0x0003: On-Since date.
272 * The time/date that the user started
273 * their current session, stored in time_t
277 outinfo->onlinesince = aimutil_get32(&buf[i+4]);
281 * Type = 0x0004: Idle time.
283 * Number of seconds since the user
284 * actively used the service.
287 outinfo->idletime = aimutil_get16(&buf[i+4]);
291 * Type = 0x0006: ICQ Online Status
293 * ICQ's Away/DND/etc "enriched" status
294 * Some decoding of values done by Scott <darkagl@pcnet.com>
297 outinfo->icqinfo.status = aimutil_get16(buf+i+2+2+2);
304 * ICQ User IP Address.
305 * Ahh, the joy of ICQ security.
308 outinfo->icqinfo.ipaddr = aimutil_get32(&buf[i+4]);
313 * random crap containing the IP address,
314 * apparently a port number, and some Other Stuff.
318 memcpy(outinfo->icqinfo.crap, &buf[i+4], 0x25);
324 * Capability information. Not real sure of
325 * actual decoding. See comment on aim_bos_setprofile()
326 * in aim_misc.c about the capability block, its the same.
332 len = aimutil_get16(buf+i+2);
336 outinfo->capabilities = aim_getcap(sess, buf+i+4, len);
343 * Unknown. Always of zero length, and always only
353 * Type = 0x000f: Session Length. (AIM)
354 * Type = 0x0010: Session Length. (AOL)
356 * The duration, in seconds, of the user's
359 * Which TLV type this comes in depends
360 * on the service the user is using (AIM or AOL).
365 outinfo->sessionlen = aimutil_get32(&buf[i+4]);
369 * Reaching here indicates that either AOL has
370 * added yet another TLV for us to deal with,
371 * or the parsing has gone Terribly Wrong.
373 * Either way, inform the owner and attempt
379 int len,z = 0, y = 0, x = 0;
382 faimdprintf(sess, 0, "userinfo: **warning: unexpected TLV:\n");
383 faimdprintf(sess, 0, "userinfo: sn =%s\n", outinfo->sn);
384 faimdprintf(sess, 0, "userinfo: curtlv=0x%04x\n", curtlv);
385 faimdprintf(sess, 0, "userinfo: type =0x%04x\n",aimutil_get16(&buf[i]));
386 faimdprintf(sess, 0, "userinfo: length=0x%04x\n", len = aimutil_get16(&buf[i+2]));
387 faimdprintf(sess, 0, "userinfo: data: \n");
390 x = snprintf(tmpstr, sizeof(tmpstr), "userinfo: ");
391 for (y = 0; y < 8; y++)
395 snprintf(tmpstr+x, sizeof(tmpstr)-x, "%02x ", buf[i+4+z]);
402 faimdprintf(sess, 0, "%s\n", tmpstr);
408 * No matter what, TLV triplets should always look like this:
412 * u_char data[length];
416 i += (2 + 2 + aimutil_get16(&buf[i+2]));
425 * Inverse of aim_extractuserinfo()
427 faim_internal int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info)
429 int i = 0, numtlv = 0;
430 struct aim_tlvlist_t *tlvlist = NULL;
435 i += aimutil_put8(buf+i, strlen(info->sn));
436 i += aimutil_putstr(buf+i, info->sn, strlen(info->sn));
438 i += aimutil_put16(buf+i, info->warnlevel);
441 aim_addtlvtochain16(&tlvlist, 0x0001, info->flags);
444 aim_addtlvtochain32(&tlvlist, 0x0002, info->membersince);
447 aim_addtlvtochain32(&tlvlist, 0x0003, info->onlinesince);
450 aim_addtlvtochain16(&tlvlist, 0x0004, info->idletime);
453 #if ICQ_OSCAR_SUPPORT
454 if(atoi(info->sn) != 0) {
455 aim_addtlvtochain16(&tlvlist, 0x0006, info->icqinfo.status);
456 aim_addtlvtochain32(&tlvlist, 0x000a, info->icqinfo.ipaddr);
460 aim_addtlvtochain_caps(&tlvlist, 0x000d, info->capabilities);
463 aim_addtlvtochain32(&tlvlist, (unsigned short)((info->flags)&AIM_FLAG_AOL?0x0010:0x000f), info->sessionlen);
466 i += aimutil_put16(buf+i, numtlv); /* tlvcount */
467 i += aim_writetlvchain(buf+i, buflen-i, &tlvlist); /* tlvs */
468 aim_freetlvchain(&tlvlist);
473 faim_export int aim_sendbuddyoncoming(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_userinfo_s *info)
475 struct command_tx_struct *tx;
478 if (!sess || !conn || !info)
481 if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152)))
486 i += aimutil_put16(tx->data+i, 0x0003);
487 i += aimutil_put16(tx->data+i, 0x000b);
488 i += aimutil_put16(tx->data+i, 0x0000);
489 i += aimutil_put16(tx->data+i, 0x0000);
490 i += aimutil_put16(tx->data+i, 0x0000);
492 i += aim_putuserinfo(tx->data+i, tx->commandlen-i, info);
496 aim_tx_enqueue(sess, tx);
501 faim_export int aim_sendbuddyoffgoing(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn)
503 struct command_tx_struct *tx;
506 if (!sess || !conn || !sn)
509 if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn))))
514 i += aimutil_put16(tx->data+i, 0x0003);
515 i += aimutil_put16(tx->data+i, 0x000c);
516 i += aimutil_put16(tx->data+i, 0x0000);
517 i += aimutil_put16(tx->data+i, 0x0000);
518 i += aimutil_put16(tx->data+i, 0x0000);
520 i += aimutil_put8(tx->data+i, strlen(sn));
521 i += aimutil_putstr(tx->data+i, sn, strlen(sn));
524 aim_tx_enqueue(sess, tx);
529 faim_export int aim_0002_000b(struct aim_session_t *sess, struct aim_conn_t *conn, const char *sn)
531 struct command_tx_struct *tx;
534 if (!sess || !conn || !sn)
537 if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn))))
542 i = aim_putsnac(tx->data, 0x0002, 0x000b, 0x0000, sess->snac_nextid);
543 i += aimutil_put8(tx->data+i, strlen(sn));
544 i += aimutil_putstr(tx->data+i, sn, strlen(sn));
548 aim_tx_enqueue(sess, tx);
553 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)
555 struct aim_tlvlist_t *tlvlist;
556 rxcallback_t userfunc;
559 tlvlist = aim_readtlvchain(data, datalen);
561 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
562 ret = userfunc(sess, rx);
564 aim_freetlvchain(&tlvlist);
569 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)
571 struct aim_userinfo_s userinfo;
572 char *text_encoding = NULL;
575 rxcallback_t userfunc;
576 struct aim_tlvlist_t *tlvlist;
577 struct aim_snac_t *origsnac = NULL;
578 struct aim_priv_inforeq *inforeq;
581 origsnac = aim_remsnac(sess, snac->id);
583 if (!origsnac || !origsnac->data) {
584 faimdprintf(sess, 0, "parse_userinfo_middle: major problem: no snac stored!\n");
588 inforeq = (struct aim_priv_inforeq *)origsnac->data;
590 if ((inforeq->infotype != AIM_GETINFO_GENERALINFO) &&
591 (inforeq->infotype != AIM_GETINFO_AWAYMESSAGE)) {
592 faimdprintf(sess, 0, "parse_userinfo_middle: unknown infotype in request! (0x%04x)\n", inforeq->infotype);
596 i = aim_extractuserinfo(sess, data, &userinfo);
598 tlvlist = aim_readtlvchain(data+i, datalen-i);
601 * Depending on what informational text was requested, different
602 * TLVs will appear here.
604 * Profile will be 1 and 2, away message will be 3 and 4.
606 if (aim_gettlv(tlvlist, 0x0001, 1)) {
607 text_encoding = aim_gettlv_str(tlvlist, 0x0001, 1);
608 text = aim_gettlv_str(tlvlist, 0x0002, 1);
609 } else if (aim_gettlv(tlvlist, 0x0003, 1)) {
610 text_encoding = aim_gettlv_str(tlvlist, 0x0003, 1);
611 text = aim_gettlv_str(tlvlist, 0x0004, 1);
614 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
615 ret = userfunc(sess, rx, &userinfo, text_encoding, text, inforeq->infotype);
620 aim_freetlvchain(&tlvlist);
624 free(origsnac->data);
631 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)
634 if (snac->subtype == 0x0003)
635 return rights(sess, mod, rx, snac, data, datalen);
636 else if (snac->subtype == 0x0006)
637 return userinfo(sess, mod, rx, snac, data, datalen);
642 faim_internal int locate_modfirst(struct aim_session_t *sess, aim_module_t *mod)
645 mod->family = 0x0002;
646 mod->version = 0x0000;
648 strncpy(mod->name, "locate", sizeof(mod->name));
649 mod->snachandler = snachandler;