5 void parser_icbm_incoming(u_char *data, int len)
7 struct aim_userinfo_s userinfo;
8 u_int i = 0, j = 0, y = 0, z = 0;
13 struct aim_tlvlist_t *tlvlist;
14 struct aim_tlv_t *msgblocktlv, *tmptlv;
19 memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s));
23 * Read ICBM Cookie. And throw away.
25 for (z=0; z<8; z++,i++)
31 * Channel 0x0001 is the message channel. There are
32 * other channels for things called "rendevous"
33 * which represent chat and some of the other new
34 * features of AIM2/3/3.5. We only support
35 * standard messages; those on channel 0x0001.
37 channel = aimutil_get16(data+i);
39 if (channel != 0x0001)
41 printf("faim: icbm: ICBM received on an unsupported channel. Ignoring.\n (chan = %04x)", channel);
48 memcpy(userinfo.sn, data+i+1, (int)data[i]);
49 userinfo.sn[(int)data[i]] = '\0';
50 i += 1 + (int)data[i];
55 wastebits = aimutil_get16(data+i);
57 wastebits = aimutil_get16(data+i);
61 * Read block of TLVs. All further data is derived
62 * from what is parsed here.
64 tlvlist = aim_readtlvchain(data+i, len-i);
67 * Check Autoresponse status. If it is an autoresponse,
68 * it will contain a second type 0x0004 TLV, with zero length.
70 if (aim_gettlv(tlvlist, 0x0004, 2))
71 icbmflags |= AIM_IMFLAGS_AWAY;
74 * Check Ack Request status.
76 if (aim_gettlv(tlvlist, 0x0003, 2))
77 icbmflags |= AIM_IMFLAGS_ACK;
80 * Extract the various pieces of the userinfo struct.
83 if ((tmptlv = aim_gettlv(tlvlist, 0x0001, 1)))
84 userinfo.class = aimutil_get16(tmptlv->value);
85 /* Member-since date. */
86 if ((tmptlv = aim_gettlv(tlvlist, 0x0002, 1)))
88 /* If this is larger than 4, its probably the message block, skip */
89 if (tmptlv->length <= 4)
90 userinfo.membersince = aimutil_get32(tmptlv->value);
93 if ((tmptlv = aim_gettlv(tlvlist, 0x0003, 1)))
94 userinfo.onlinesince = aimutil_get32(tmptlv->value);
96 if ((tmptlv = aim_gettlv(tlvlist, 0x0004, 1)))
97 userinfo.idletime = aimutil_get16(tmptlv->value);
98 /* Session Length (AIM) */
99 if ((tmptlv = aim_gettlv(tlvlist, 0x000f, 1)))
100 userinfo.sessionlen = aimutil_get16(tmptlv->value);
101 /* Session Length (AOL) */
102 if ((tmptlv = aim_gettlv(tlvlist, 0x0010, 1)))
103 userinfo.sessionlen = aimutil_get16(tmptlv->value);
108 * XXX: Will the msgblock always be the second 0x0002?
110 msgblocktlv = aim_gettlv(tlvlist, 0x0002, 1);
113 printf("faim: icbm: major error! no message block TLV found!\n");
114 aim_freetlvchain(&tlvlist);
118 * Extracting the message from the unknown cruft.
120 * This is a bit messy, and I'm not really qualified,
121 * even as the author, to comment on it. At least
122 * its not as bad as a while loop shooting into infinity.
124 * "Do you believe in magic?"
127 msgblock = msgblocktlv->value;
130 wastebits = aimutil_get8(msgblock+j++);
131 wastebits = aimutil_get8(msgblock+j++);
133 y = aimutil_get16(msgblock+j);
135 for (z = 0; z < y; z++)
136 wastebits = aimutil_get8(msgblock+j++);
137 wastebits = aimutil_get8(msgblock+j++);
138 wastebits = aimutil_get8(msgblock+j++);
141 * Message string length, including flag words.
143 i = aimutil_get16(msgblock+j);
149 * Its rumored that these can kick in some funky
150 * 16bit-wide char stuff that used to really kill
151 * libfaim. Hopefully the latter is no longer true.
153 * Though someone should investiagte the former.
156 flag1 = aimutil_get16(msgblock+j);
158 flag2 = aimutil_get16(msgblock+j);
162 printf("faim: icbm: **warning: encoding flags are being used! {%04x, %04x}\n", flag1, flag2);
168 msg = (char *)malloc(i+1);
169 memcpy(msg, msgblock+j, i);
173 * Free up the TLV chain.
175 aim_freetlvchain(&tlvlist);
178 printf("\tChannel:\t0x%04x\n", channel);
179 printf("\tSource:\t%s\n", userinfo.sn);
180 printf("\tICBM Flags:\t%s %s\n",
181 (icbmflags & AIM_IMFLAGS_AWAY)?"Away":"",
182 (icbmflags & AIM_IMFLAGS_ACK)?"Ack":"");
183 printf("\tEncoding Flags:\t{0x%02x, 0x%02x}\n", flag1, flag2);
184 printf("\tMessage:\n");
185 printf("\t\t%s\n", msg);