4 * The functions here are responsible for requesting and parsing information-
12 u_long aim_getinfo(struct aim_session_t *sess,
13 struct aim_conn_t *conn,
16 struct command_tx_struct newpacket;
19 if (!sess || !conn || !sn)
23 newpacket.conn = conn;
25 newpacket.conn = aim_getconn_type(sess, AIM_CONN_TYPE_BOS);
28 newpacket.type = 0x0002;
30 newpacket.commandlen = 12 + 1 + strlen(sn);
31 newpacket.data = (char *) malloc(newpacket.commandlen);
33 i = aim_putsnac(newpacket.data, 0x0002, 0x0005, 0x0000, sess->snac_nextid);
35 i += aimutil_put16(newpacket.data+i, 0x0001);
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;
46 printf("faim: getuserinfo: caching snac %08lx\n", snac.id);
51 snac.data = malloc(strlen(sn)+1);
52 strcpy(snac.data, sn);
54 aim_newsnac(sess, &snac);
57 return (sess->snac_nextid++);
61 * AIM is fairly regular about providing user info. This
62 * is a generic routine to extract it in its standard form.
64 int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinfo)
76 /* Clear out old data first */
77 memset(outinfo, 0x00, sizeof(struct aim_userinfo_s));
80 * Screen name. Stored as an unterminated string prepended
81 * with an unsigned byte containing its length.
83 memcpy(outinfo->sn, &(buf[i+1]), buf[i]);
84 outinfo->sn[(int)buf[i]] = '\0';
88 * Warning Level. Stored as an unsigned short.
90 outinfo->warnlevel = aimutil_get16(&buf[i]);
94 * TLV Count. Unsigned short representing the number of
95 * Type-Length-Value triples that follow.
97 tlvcnt = aimutil_get16(&buf[i]);
101 * Parse out the Type-Length-Value triples as they're found.
103 while (curtlv < tlvcnt)
105 curtype = aimutil_get16(&buf[i]);
109 * Type = 0x0001: Member Class.
111 * Specified as any of the following bitwise ORed together:
112 * 0x0001 Trial (user less than 60days)
113 * 0x0002 Unknown bit 2
114 * 0x0004 AOL Main Service user
115 * 0x0008 Unknown bit 4
116 * 0x0010 Free (AIM) user
119 * In some odd cases, we can end up with more
120 * than one of these. We only want the first,
121 * as the others may not be something we want.
125 if (tlv1) /* use only the first */
127 outinfo->class = aimutil_get16(&buf[i+4]);
132 * Type = 0x0002: Member-Since date.
134 * The time/date that the user originally
135 * registered for the service, stored in
139 outinfo->membersince = aimutil_get32(&buf[i+4]);
143 * Type = 0x0003: On-Since date.
145 * The time/date that the user started
146 * their current session, stored in time_t
150 outinfo->onlinesince = aimutil_get32(&buf[i+4]);
154 * Type = 0x0004: Idle time.
156 * Number of seconds since the user
157 * actively used the service.
160 outinfo->idletime = aimutil_get16(&buf[i+4]);
166 * Capability information. Not real sure of
167 * actual decoding. See comment on aim_bos_setprofile()
168 * in aim_misc.c about the capability block, its the same.
179 * Unknown. Always of zero length, and always only
189 * Type = 0x000f: Session Length. (AIM)
190 * Type = 0x0010: Session Length. (AOL)
192 * The duration, in seconds, of the user's
195 * Which TLV type this comes in depends
196 * on the service the user is using (AIM or AOL).
201 outinfo->sessionlen = aimutil_get32(&buf[i+4]);
205 * Reaching here indicates that either AOL has
206 * added yet another TLV for us to deal with,
207 * or the parsing has gone Terribly Wrong.
209 * Either way, inform the owner and attempt
215 int len,z = 0, y = 0, x = 0;
217 printf("faim: userinfo: **warning: unexpected TLV:\n");
218 printf("faim: userinfo: sn =%s\n", outinfo->sn);
219 printf("faim: userinfo: curtlv=0x%04x\n", curtlv);
220 printf("faim: userinfo: type =0x%04x\n",aimutil_get16(&buf[i]));
221 printf("faim: userinfo: length=0x%04x\n", len = aimutil_get16(&buf[i+2]));
222 printf("faim: userinfo: data: \n");
225 x = sprintf(tmpstr, "faim: userinfo: ");
226 for (y = 0; y < 8; y++)
230 sprintf(tmpstr+x, "%02x ", buf[i+4+z]);
237 printf("%s\n", tmpstr);
243 * No matter what, TLV triplets should always look like this:
247 * u_char data[length];
250 i += (2 + 2 + aimutil_get16(&buf[i+2]));
259 * Oncoming Buddy notifications contain a subset of the
260 * user information structure. Its close enough to run
261 * through aim_extractuserinfo() however.
264 int aim_parse_oncoming_middle(struct aim_session_t *sess,
265 struct command_rx_struct *command)
267 struct aim_userinfo_s userinfo;
269 rxcallback_t userfunc=NULL;
272 i += aim_extractuserinfo(command->data+i, &userinfo);
274 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING);
276 i = userfunc(sess, command, &userinfo);
282 * Offgoing Buddy notifications contain no useful
283 * information other than the name it applies to.
286 int aim_parse_offgoing_middle(struct aim_session_t *sess,
287 struct command_rx_struct *command)
291 rxcallback_t userfunc=NULL;
293 strncpy(sn, command->data+11, (int)command->data[10]);
294 sn[(int)command->data[10]] = '\0';
296 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING);
298 i = userfunc(sess, command, sn);
304 * This parses the user info stuff out all nice and pretty then calls
305 * the higher-level callback (in the user app).
308 int aim_parse_userinfo_middle(struct aim_session_t *sess,
309 struct command_rx_struct *command)
311 struct aim_userinfo_s userinfo;
312 char *prof_encoding = NULL;
315 rxcallback_t userfunc=NULL;
316 struct aim_tlvlist_t *tlvlist;
319 u_long snacid = 0x000000000;
320 struct aim_snac_t *snac = NULL;
322 snacid = aimutil_get32(&command->data[6]);
323 snac = aim_remsnac(sess, snacid);
330 printf("faim: parse_userinfo_middle: warning: no ->data in cached SNAC\n");
334 printf("faim: parseuserinfo_middle: warning: no SNAC cached with for this response (%08lx)\n", snacid);
341 * extractuserinfo will give us the basic metaTLV information
343 i += aim_extractuserinfo(command->data+i, &userinfo);
346 * However, in this command, there's usually more TLVs following...
348 tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
349 prof_encoding = aim_gettlv_str(tlvlist, 0x0001, 1);
350 prof = aim_gettlv_str(tlvlist, 0x0002, 1);
352 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO);
364 aim_freetlvchain(&tlvlist);