4 * The functions here are responsible for requesting and parsing information-
12 struct aim_priv_inforeq {
14 unsigned short infotype;
17 u_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(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++);
64 u_char aim_caps[6][16] = {
67 {0x09, 0x46, 0x13, 0x46, 0x4c, 0x7f, 0x11, 0xd1,
68 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
71 {0x09, 0x46, 0x13, 0x41, 0x4c, 0x7f, 0x11, 0xd1,
72 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
75 {0x09, 0x46, 0x13, 0x45, 0x4c, 0x7f, 0x11, 0xd1,
76 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
79 {0x74, 0x8f, 0x24, 0x20, 0x62, 0x87, 0x11, 0xd1,
80 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
83 {0x09, 0x46, 0x13, 0x48, 0x4c, 0x7f, 0x11, 0xd1,
84 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
87 {0x09, 0x46, 0x13, 0x43, 0x4c, 0x7f, 0x11, 0xd1,
88 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}
92 * AIM is fairly regular about providing user info. This
93 * is a generic routine to extract it in its standard form.
95 int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinfo)
104 if (!buf || !outinfo)
107 /* Clear out old data first */
108 memset(outinfo, 0x00, sizeof(struct aim_userinfo_s));
111 * Screen name. Stored as an unterminated string prepended
112 * with an unsigned byte containing its length.
114 memcpy(outinfo->sn, &(buf[i+1]), buf[i]);
115 outinfo->sn[(int)buf[i]] = '\0';
119 * Warning Level. Stored as an unsigned short.
121 outinfo->warnlevel = aimutil_get16(&buf[i]);
125 * TLV Count. Unsigned short representing the number of
126 * Type-Length-Value triples that follow.
128 tlvcnt = aimutil_get16(&buf[i]);
132 * Parse out the Type-Length-Value triples as they're found.
134 while (curtlv < tlvcnt)
136 curtype = aimutil_get16(&buf[i]);
140 * Type = 0x0001: Member Class.
142 * Specified as any of the following bitwise ORed together:
143 * 0x0001 Trial (user less than 60days)
144 * 0x0002 Unknown bit 2
145 * 0x0004 AOL Main Service user
146 * 0x0008 Unknown bit 4
147 * 0x0010 Free (AIM) user
150 * In some odd cases, we can end up with more
151 * than one of these. We only want the first,
152 * as the others may not be something we want.
156 if (tlv1) /* use only the first */
158 outinfo->class = aimutil_get16(&buf[i+4]);
163 * Type = 0x0002: Member-Since date.
165 * The time/date that the user originally
166 * registered for the service, stored in
170 outinfo->membersince = aimutil_get32(&buf[i+4]);
174 * Type = 0x0003: On-Since date.
176 * The time/date that the user started
177 * their current session, stored in time_t
181 outinfo->onlinesince = aimutil_get32(&buf[i+4]);
185 * Type = 0x0004: Idle time.
187 * Number of seconds since the user
188 * actively used the service.
191 outinfo->idletime = aimutil_get16(&buf[i+4]);
197 * Capability information. Not real sure of
198 * actual decoding. See comment on aim_bos_setprofile()
199 * in aim_misc.c about the capability block, its the same.
208 len = aimutil_get16(buf+i+2);
212 for (z = 0; z < len; z+=0x10) {
213 for(y=0; y < 6; y++) {
214 if (memcmp(&aim_caps[y], buf+i+4+z, 0x10) == 0) {
216 case 0: outinfo->capabilities |= AIM_CAPS_BUDDYICON; break;
217 case 1: outinfo->capabilities |= AIM_CAPS_VOICE; break;
218 case 2: outinfo->capabilities |= AIM_CAPS_IMIMAGE; break;
219 case 3: outinfo->capabilities |= AIM_CAPS_CHAT; break;
220 case 4: outinfo->capabilities |= AIM_CAPS_GETFILE; break;
221 case 5: outinfo->capabilities |= AIM_CAPS_SENDFILE; break;
222 default: outinfo->capabilities |= 0xff00; break;
233 * Unknown. Always of zero length, and always only
243 * Type = 0x000f: Session Length. (AIM)
244 * Type = 0x0010: Session Length. (AOL)
246 * The duration, in seconds, of the user's
249 * Which TLV type this comes in depends
250 * on the service the user is using (AIM or AOL).
255 outinfo->sessionlen = aimutil_get32(&buf[i+4]);
259 * Reaching here indicates that either AOL has
260 * added yet another TLV for us to deal with,
261 * or the parsing has gone Terribly Wrong.
263 * Either way, inform the owner and attempt
269 int len,z = 0, y = 0, x = 0;
271 printf("faim: userinfo: **warning: unexpected TLV:\n");
272 printf("faim: userinfo: sn =%s\n", outinfo->sn);
273 printf("faim: userinfo: curtlv=0x%04x\n", curtlv);
274 printf("faim: userinfo: type =0x%04x\n",aimutil_get16(&buf[i]));
275 printf("faim: userinfo: length=0x%04x\n", len = aimutil_get16(&buf[i+2]));
276 printf("faim: userinfo: data: \n");
279 x = sprintf(tmpstr, "faim: userinfo: ");
280 for (y = 0; y < 8; y++)
284 sprintf(tmpstr+x, "%02x ", buf[i+4+z]);
291 printf("%s\n", tmpstr);
297 * No matter what, TLV triplets should always look like this:
301 * u_char data[length];
304 i += (2 + 2 + aimutil_get16(&buf[i+2]));
313 * Oncoming Buddy notifications contain a subset of the
314 * user information structure. Its close enough to run
315 * through aim_extractuserinfo() however.
318 int aim_parse_oncoming_middle(struct aim_session_t *sess,
319 struct command_rx_struct *command)
321 struct aim_userinfo_s userinfo;
323 rxcallback_t userfunc=NULL;
326 i += aim_extractuserinfo(command->data+i, &userinfo);
328 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING);
330 i = userfunc(sess, command, &userinfo);
336 * Offgoing Buddy notifications contain no useful
337 * information other than the name it applies to.
340 int aim_parse_offgoing_middle(struct aim_session_t *sess,
341 struct command_rx_struct *command)
345 rxcallback_t userfunc=NULL;
347 strncpy(sn, command->data+11, (int)command->data[10]);
348 sn[(int)command->data[10]] = '\0';
350 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING);
352 i = userfunc(sess, command, sn);
358 * This parses the user info stuff out all nice and pretty then calls
359 * the higher-level callback (in the user app).
362 int aim_parse_userinfo_middle(struct aim_session_t *sess,
363 struct command_rx_struct *command)
365 struct aim_userinfo_s userinfo;
366 char *text_encoding = NULL;
369 rxcallback_t userfunc=NULL;
370 struct aim_tlvlist_t *tlvlist;
371 struct aim_snac_t *origsnac = NULL;
373 struct aim_priv_inforeq *inforeq;
375 snacid = aimutil_get32(&command->data[6]);
376 origsnac = aim_remsnac(sess, snacid);
378 if (!origsnac || !origsnac->data) {
379 printf("faim: parse_userinfo_middle: major problem: no snac stored!\n");
383 inforeq = (struct aim_priv_inforeq *)origsnac->data;
385 switch (inforeq->infotype) {
386 case AIM_GETINFO_GENERALINFO:
387 case AIM_GETINFO_AWAYMESSAGE:
391 * extractuserinfo will give us the basic metaTLV information
393 i += aim_extractuserinfo(command->data+i, &userinfo);
396 * However, in this command, there's usually more TLVs following...
398 tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
401 * Depending on what informational text was requested, different
402 * TLVs will appear here.
404 * Profile will be 1 and 2, away message will be 3 and 4.
406 if (aim_gettlv(tlvlist, 0x0001, 1)) {
407 text_encoding = aim_gettlv_str(tlvlist, 0x0001, 1);
408 text = aim_gettlv_str(tlvlist, 0x0002, 1);
409 } else if (aim_gettlv(tlvlist, 0x0003, 1)) {
410 text_encoding = aim_gettlv_str(tlvlist, 0x0003, 1);
411 text = aim_gettlv_str(tlvlist, 0x0004, 1);
414 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO);
426 aim_freetlvchain(&tlvlist);
429 printf("faim: parse_userinfo_middle: unknown infotype in request! (0x%04x)\n", inforeq->infotype);
435 free(origsnac->data);
443 * Inverse of aim_extractuserinfo()
445 int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info)
448 struct aim_tlvlist_t *tlvlist = NULL;
453 i += aimutil_put8(buf+i, strlen(info->sn));
454 i += aimutil_putstr(buf+i, info->sn, strlen(info->sn));
456 i += aimutil_put16(buf+i, info->warnlevel);
458 /* XXX: we only put down five */
459 i += aimutil_put16(buf+i, 5);
460 aim_addtlvtochain16(&tlvlist, 0x0001, info->class);
461 aim_addtlvtochain32(&tlvlist, 0x0002, info->membersince);
462 aim_addtlvtochain32(&tlvlist, 0x0003, info->onlinesince);
463 aim_addtlvtochain16(&tlvlist, 0x0004, info->idletime);
464 /* XXX: should put caps here */
465 aim_addtlvtochain32(&tlvlist, (info->class)&AIM_CLASS_AOL?0x0010:0x000f, info->sessionlen);
467 i += aim_writetlvchain(buf+i, buflen-i, &tlvlist);
468 aim_freetlvchain(&tlvlist);
473 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(0x0002, conn, 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 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(0x0002, conn, 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);