+ /*
+ * The rest of the handling depends on what type it is.
+ */
+ if (args.reqclass & AIM_CAPS_BUDDYICON) {
+ struct aim_tlv_t *miscinfo;
+ int curpos = 0;
+
+ miscinfo = aim_gettlv(list2, 0x2711, 1);
+
+ /* aimutil_get32(miscinfo->value+curpos); i don't know what this is */
+ curpos += 4;
+ args.info.icon.length = aimutil_get32(miscinfo->value+curpos);
+ curpos += 4;
+ args.info.icon.timestamp = aimutil_get32(miscinfo->value+curpos);
+ curpos += 4;
+ args.info.icon.icon = malloc(args.info.icon.length);
+ memcpy(args.info.icon.icon, miscinfo->value+curpos, args.info.icon.length);
+
+ if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
+ ret = userfunc(sess, rx, channel, userinfo, &args);
+
+ free(args.info.icon.icon);
+
+ } else if (args.reqclass & AIM_CAPS_VOICE) {
+ struct aim_msgcookie_t *cachedcook;
+
+ faimdprintf(sess, 1, "rend: voice!\n");
+
+ if(!(cachedcook = (struct aim_msgcookie_t*)calloc(1, sizeof(struct aim_msgcookie_t)))) {
+ aim_freetlvchain(&list2);
+ return 0;
+ }
+
+ memcpy(cachedcook->cookie, cookie, 8);
+ cachedcook->type = AIM_COOKIETYPE_OFTVOICE;
+ cachedcook->data = NULL;
+
+ if (aim_cachecookie(sess, cachedcook) == -1)
+ faimdprintf(sess, 0, "ERROR caching message cookie\n");
+
+ /* XXX: implement all this */
+
+ if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
+ ret = userfunc(sess, rx, channel, userinfo, &args);
+
+ } else if (args.reqclass & AIM_CAPS_IMIMAGE) {
+ char ip[30];
+ struct aim_directim_priv *priv;
+
+ memset(ip, 0, sizeof(ip));
+
+ if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
+ struct aim_tlv_t *iptlv, *porttlv;
+
+ iptlv = aim_gettlv(list2, 0x0003, 1);
+ porttlv = aim_gettlv(list2, 0x0005, 1);
+
+ snprintf(ip, 30, "%d.%d.%d.%d:%d",
+ aimutil_get8(iptlv->value+0),
+ aimutil_get8(iptlv->value+1),
+ aimutil_get8(iptlv->value+2),
+ aimutil_get8(iptlv->value+3),
+ 4443 /*aimutil_get16(porttlv->value)*/);
+ }
+
+ faimdprintf(sess, 1, "rend: directIM request from %s (%s)\n",
+ userinfo->sn, ip);
+
+ /*
+ * XXX: there are a couple of different request packets for
+ * different things
+ */
+
+ args.info.directim = priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv)); /* XXX error */
+ memcpy(priv->ip, ip, sizeof(priv->ip));
+ memcpy(priv->sn, userinfo->sn, sizeof(priv->sn));
+ memcpy(priv->cookie, cookie, sizeof(priv->cookie));
+
+ if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
+ ret = userfunc(sess, rx, channel, userinfo, &args);
+
+ } else if (args.reqclass & AIM_CAPS_CHAT) {
+ struct aim_tlv_t *miscinfo;
+
+ miscinfo = aim_gettlv(list2, 0x2711, 1);
+ aim_chat_readroominfo(miscinfo->value, &args.info.chat.roominfo);
+
+ if (aim_gettlv(list2, 0x000c, 1))
+ args.info.chat.msg = aim_gettlv_str(list2, 0x000c, 1);
+
+ if (aim_gettlv(list2, 0x000d, 1))
+ args.info.chat.encoding = aim_gettlv_str(list2, 0x000d, 1);
+
+ if (aim_gettlv(list2, 0x000e, 1))
+ args.info.chat.lang = aim_gettlv_str(list2, 0x000e, 1);
+
+ if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
+ ret = userfunc(sess, rx, channel, userinfo, &args);
+
+ free(args.info.chat.roominfo.name);
+ free(args.info.chat.msg);
+ free(args.info.chat.encoding);
+ free(args.info.chat.lang);
+
+ } else if (args.reqclass & AIM_CAPS_GETFILE) {
+ char ip[30];
+ struct aim_msgcookie_t *cachedcook;
+ struct aim_tlv_t *miscinfo;
+ struct aim_tlv_t *iptlv, *porttlv;
+
+ memset(ip, 0, 30);
+
+ if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t)))) {
+ aim_freetlvchain(&list2);
+ return 0;
+ }
+
+ if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)) ||
+ !(iptlv = aim_gettlv(list2, 0x0003, 1)) ||
+ !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
+
+ faimdprintf(sess, 0, "rend: badly damaged file get request from %s...\n", userinfo->sn);
+ aim_cookie_free(sess, cachedcook);
+ aim_freetlvchain(&list2);
+
+ return 0;
+ }
+
+ snprintf(ip, 30, "%d.%d.%d.%d:%d",
+ aimutil_get8(iptlv->value+0),
+ aimutil_get8(iptlv->value+1),
+ aimutil_get8(iptlv->value+2),
+ aimutil_get8(iptlv->value+3),
+ aimutil_get16(porttlv->value));
+
+ faimdprintf(sess, 0, "rend: file get request from %s (%s)\n", userinfo->sn, ip);
+
+ args.info.getfile.ip = ip;
+ args.info.getfile.cookie = cookie;
+
+ if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
+ ret = userfunc(sess, rx, channel, userinfo, &args);
+
+ } else if (args.reqclass & AIM_CAPS_SENDFILE) {
+#if 0
+ char ip[30];
+ struct aim_msgcookie_t *cachedcook;
+ struct aim_tlv_t *miscinfo;
+ struct aim_tlv_t *iptlv, *porttlv;
+
+ memset(ip, 0, 30);
+
+ if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t)))) {
+ aim_freetlvchain(&list2);
+ return 0;
+ }
+
+ if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)) ||
+ !(iptlv = aim_gettlv(list2, 0x0003, 1)) ||
+ !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
+
+ faimdprintf(sess, 0, "rend: badly damaged file get request from %s...\n", userinfo->sn);
+ aim_cookie_free(sess, cachedcook);
+ aim_freetlvchain(&list2);
+
+ return 0;
+ }
+
+ snprintf(ip, 30, "%d.%d.%d.%d:%d",
+ aimutil_get8(iptlv->value+0),
+ aimutil_get8(iptlv->value+1),
+ aimutil_get8(iptlv->value+2),
+ aimutil_get8(iptlv->value+3),
+ aimutil_get16(porttlv->value));
+
+ if (aim_gettlv(list2, 0x000c, 1))
+ desc = aim_gettlv_str(list2, 0x000c, 1);
+
+ faimdprintf(sess, 0, "rend: file transfer request from %s: %s (%s)\n",
+ userinfo->sn, desc, ip);
+
+ memcpy(cachedcook->cookie, cookie, 8);
+
+ ft = malloc(sizeof(struct aim_filetransfer_priv)); /* XXX */
+ strncpy(ft->sn, userinfo.sn, sizeof(ft->sn));
+ strncpy(ft->ip, ip, sizeof(ft->ip));
+ strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name));
+ cachedcook->type = AIM_COOKIETYPE_OFTSEND;
+ cachedcook->data = ft;
+
+ if (aim_cachecookie(sess, cachedcook) == -1)
+ faimdprintf(sess, 0, "ERROR caching message cookie\n");
+
+ aim_accepttransfer(sess, rx->conn, ft->sn, cookie, AIM_CAPS_SENDFILE);
+
+ if (desc)
+ free(desc);
+
+ if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
+ ret = userfunc(sess, rx, channel, userinfo, &args);
+
+#endif
+ } else
+ faimdprintf(sess, 0, "rend: unknown rendezvous 0x%04x\n", args.reqclass);
+
+ aim_freetlvchain(&list2);
+
+ return ret;
+}
+
+/*
+ * It can easily be said that parsing ICBMs is THE single
+ * most difficult thing to do in the in AIM protocol. In
+ * fact, I think I just did say that.
+ *
+ * Below is the best damned solution I've come up with
+ * over the past sixteen months of battling with it. This
+ * can parse both away and normal messages from every client
+ * I have access to. Its not fast, its not clean. But it works.
+ *
+ */
+static int incomingim(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
+{
+ int i, ret = 0;
+ unsigned char cookie[8];
+ int channel;
+ struct aim_userinfo_s userinfo;
+
+ memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s));