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;
50 snac.data = malloc(strlen(sn)+1);
51 strcpy(snac.data, sn);
53 aim_newsnac(sess, &snac);
56 return (sess->snac_nextid++);
60 * AIM is fairly regular about providing user info. This
61 * is a generic routine to extract it in its standard form.
63 int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinfo)
75 /* Clear out old data first */
76 memset(outinfo, 0x00, sizeof(struct aim_userinfo_s));
79 * Screen name. Stored as an unterminated string prepended
80 * with an unsigned byte containing its length.
82 memcpy(outinfo->sn, &(buf[i+1]), buf[i]);
83 outinfo->sn[(int)buf[i]] = '\0';
87 * Warning Level. Stored as an unsigned short.
89 outinfo->warnlevel = aimutil_get16(&buf[i]);
93 * TLV Count. Unsigned short representing the number of
94 * Type-Length-Value triples that follow.
96 tlvcnt = aimutil_get16(&buf[i]);
100 * Parse out the Type-Length-Value triples as they're found.
102 while (curtlv < tlvcnt)
104 curtype = aimutil_get16(&buf[i]);
108 * Type = 0x0001: Member Class.
110 * Specified as any of the following bitwise ORed together:
111 * 0x0001 Trial (user less than 60days)
112 * 0x0002 Unknown bit 2
113 * 0x0004 AOL Main Service user
114 * 0x0008 Unknown bit 4
115 * 0x0010 Free (AIM) user
118 * In some odd cases, we can end up with more
119 * than one of these. We only want the first,
120 * as the others may not be something we want.
124 if (tlv1) /* use only the first */
126 outinfo->class = aimutil_get16(&buf[i+4]);
131 * Type = 0x0002: Member-Since date.
133 * The time/date that the user originally
134 * registered for the service, stored in
138 outinfo->membersince = aimutil_get32(&buf[i+4]);
142 * Type = 0x0003: On-Since date.
144 * The time/date that the user started
145 * their current session, stored in time_t
149 outinfo->onlinesince = aimutil_get32(&buf[i+4]);
153 * Type = 0x0004: Idle time.
155 * Number of seconds since the user
156 * actively used the service.
159 outinfo->idletime = aimutil_get16(&buf[i+4]);
165 * Capability information. Not real sure of
166 * actual decoding. See comment on aim_bos_setprofile()
167 * in aim_misc.c about the capability block, its the same.
178 * Unknown. Always of zero length, and always only
188 * Type = 0x000f: Session Length. (AIM)
189 * Type = 0x0010: Session Length. (AOL)
191 * The duration, in seconds, of the user's
194 * Which TLV type this comes in depends
195 * on the service the user is using (AIM or AOL).
200 outinfo->sessionlen = aimutil_get32(&buf[i+4]);
204 * Reaching here indicates that either AOL has
205 * added yet another TLV for us to deal with,
206 * or the parsing has gone Terribly Wrong.
208 * Either way, inform the owner and attempt
214 int len,z = 0, y = 0, x = 0;
216 printf("faim: userinfo: **warning: unexpected TLV:\n");
217 printf("faim: userinfo: sn =%s\n", outinfo->sn);
218 printf("faim: userinfo: curtlv=0x%04x\n", curtlv);
219 printf("faim: userinfo: type =0x%04x\n",aimutil_get16(&buf[i]));
220 printf("faim: userinfo: length=0x%04x\n", len = aimutil_get16(&buf[i+2]));
221 printf("faim: userinfo: data: \n");
224 x = sprintf(tmpstr, "faim: userinfo: ");
225 for (y = 0; y < 8; y++)
229 sprintf(tmpstr+x, "%02x ", buf[i+4+z]);
236 printf("%s\n", tmpstr);
242 * No matter what, TLV triplets should always look like this:
246 * u_char data[length];
249 i += (2 + 2 + aimutil_get16(&buf[i+2]));
258 * Oncoming Buddy notifications contain a subset of the
259 * user information structure. Its close enough to run
260 * through aim_extractuserinfo() however.
263 int aim_parse_oncoming_middle(struct aim_session_t *sess,
264 struct command_rx_struct *command)
266 struct aim_userinfo_s userinfo;
268 rxcallback_t userfunc=NULL;
271 i += aim_extractuserinfo(command->data+i, &userinfo);
273 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING);
275 i = userfunc(sess, command, &userinfo);
281 * Offgoing Buddy notifications contain no useful
282 * information other than the name it applies to.
285 int aim_parse_offgoing_middle(struct aim_session_t *sess,
286 struct command_rx_struct *command)
290 rxcallback_t userfunc=NULL;
292 strncpy(sn, command->data+11, (int)command->data[10]);
293 sn[(int)command->data[10]] = '\0';
295 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING);
297 i = userfunc(sess, command, sn);
303 * This parses the user info stuff out all nice and pretty then calls
304 * the higher-level callback (in the user app).
307 int aim_parse_userinfo_middle(struct aim_session_t *sess,
308 struct command_rx_struct *command)
310 struct aim_userinfo_s userinfo;
311 char *prof_encoding = NULL;
314 rxcallback_t userfunc=NULL;
315 struct aim_tlvlist_t *tlvlist;
318 u_long snacid = 0x000000000;
319 struct aim_snac_t *snac = NULL;
321 snacid = aimutil_get32(&command->data[6]);
322 snac = aim_remsnac(sess, snacid);
329 printf("faim: parse_userinfo_middle: warning: no ->data in cached SNAC\n");
333 printf("faim: parseuserinfo_middle: warning: no SNAC cached with for this response (%08lx)\n", snacid);
340 * extractuserinfo will give us the basic metaTLV information
342 i += aim_extractuserinfo(command->data+i, &userinfo);
345 * However, in this command, there's usually more TLVs following...
347 tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
348 prof_encoding = aim_gettlv_str(tlvlist, 0x0001, 1);
349 prof = aim_gettlv_str(tlvlist, 0x0002, 1);
351 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO);
363 aim_freetlvchain(&tlvlist);