*/
faim_export int aim_send_im_ext(aim_session_t *sess, aim_conn_t *conn, struct aim_sendimext_args *args)
{
- int i;
+ static const fu8_t deffeatures[] = {
+ 0x01, 0x01, 0x01, 0x02, 0x42,
+ };
+ int i, msgtlvlen;
aim_frame_t *fr;
aim_snacid_t snacid;
if (args->msglen >= MAXMSGLEN)
return -E2BIG;
+ msgtlvlen = 12 + args->msglen;
+ if (args->flags & AIM_IMFLAGS_CUSTOMFEATURES)
+ msgtlvlen += args->featureslen;
+ else
+ msgtlvlen += sizeof(deffeatures);
+
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, args->msglen+512)))
return -ENOMEM;
* metaTLV start.
*/
aimbs_put16(&fr->data, 0x0002);
- aimbs_put16(&fr->data, args->msglen + 0x10);
+ aimbs_put16(&fr->data, msgtlvlen);
/*
- * Flag data / ICBM Parameters?
- *
- * I don't know what these are...
+ * Features
*
*/
aimbs_put8(&fr->data, 0x05);
aimbs_put8(&fr->data, 0x01);
- /* number of bytes to follow */
- aimbs_put16(&fr->data, 0x0004);
- aimbs_put8(&fr->data, 0x01);
- aimbs_put8(&fr->data, 0x01);
- aimbs_put8(&fr->data, 0x01);
- aimbs_put8(&fr->data, 0x02);
+ if (args->flags & AIM_IMFLAGS_CUSTOMFEATURES) {
+ aimbs_put16(&fr->data, args->featureslen);
+ aimbs_putraw(&fr->data, args->features, args->featureslen);
+ } else {
+ aimbs_put16(&fr->data, sizeof(deffeatures));
+ aimbs_putraw(&fr->data, deffeatures, sizeof(deffeatures));
+ }
aimbs_put16(&fr->data, 0x0101);
args.msg = msg;
args.msglen = strlen(msg);
+ /* Make these don't get set by accident -- they need aim_send_im_ext */
+ args.flags &= ~(AIM_IMFLAGS_CUSTOMFEATURES | AIM_IMFLAGS_HASICON);
+
return aim_send_im_ext(sess, conn, &args);
}
endpos = aim_bstream_curpos(bs) + length;
if (type == 0x0002) { /* Message Block */
- fu16_t featureslen;
- int z;
/*
* This TLV consists of the following:
aimbs_get8(bs); /* 05 */
aimbs_get8(bs); /* 01 */
- featureslen = aimbs_get16(bs);
- for (z = 0, args.finlen = 0; z < featureslen; z++) {
- fu8_t tmp;
-
- tmp = aimbs_get8(bs);
- if (z < sizeof(args.fingerprint)) {
- args.fingerprint[z] = tmp;
- args.finlen++;
- }
- }
+
+ args.featureslen = aimbs_get16(bs);
+ /* XXX XXX this is all evil! */
+ args.features = bs->data + bs->offset;
+ aim_bstream_advance(bs, args.featureslen);
+ args.icbmflags |= AIM_IMFLAGS_CUSTOMFEATURES;
+
aimbs_get8(bs); /* 01 */
aimbs_get8(bs); /* 01 */
} else if (type == 0x0008) { /* I-HAVE-A-REALLY-PURTY-ICON Flag */
- args.iconchecksum = aimbs_get32(bs);
- args.iconlength = aimbs_get32(bs);
+ args.iconsum = aimbs_get32(bs);
+ args.iconlen = aimbs_get32(bs);
args.iconstamp = aimbs_get32(bs);
args.icbmflags |= AIM_IMFLAGS_HASICON;
return ret;
}
+static int incomingim_ch2_buddyicon(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2)
+{
+ aim_rxcallback_t userfunc;
+ int ret = 0;
+ aim_tlv_t *miscinfo;
+ aim_bstream_t tbs;
+
+ miscinfo = aim_gettlv(list2, 0x2711, 1);
+ aim_bstream_init(&tbs, miscinfo->value, miscinfo->length);
+
+ args->info.icon.checksum = aimbs_get32(&tbs);
+ args->info.icon.length = aimbs_get32(&tbs);
+ args->info.icon.timestamp = aimbs_get32(&tbs);
+ args->info.icon.icon = aimbs_getraw(&tbs, args->info.icon.length);
+
+ if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
+ ret = userfunc(sess, rx, 0x0002, userinfo, args);
+
+ free(args->info.icon.icon);
+
+ return ret;
+}
+
+static int incomingim_ch2_imimage(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2)
+{
+ aim_rxcallback_t userfunc;
+ int ret = 0;
+
+ /* Primary IP address */
+ if (aim_gettlv(list2, 0x0003, 1)) {
+ aim_tlv_t *tlv;
+
+ tlv = aim_gettlv(list2, 0x0003, 1);
+
+ snprintf(args->info.imimage.ip, sizeof(args->info.imimage.ip),
+ "%d.%d.%d.%d:4443",
+ tlv->value[0],
+ tlv->value[1],
+ tlv->value[2],
+ tlv->value[3]);
+ }
+
+ /*
+ * Alternate IP address
+ *
+ * Sort of. The peer doesn't send this -- the OSCAR
+ * server does. So it will be the IP address that the
+ * peer is directly connected to the internet with, which
+ * may not be the same as the IP above. If these two
+ * values differ, it's rather unlikely that this
+ * rendezvous is going to happen...
+ *
+ */
+ if (aim_gettlv(list2, 0x0004, 1))
+ ;
+
+ /* Port number (not correct -- ignore) */
+ if (aim_gettlv(list2, 0x0005, 1))
+ ;
+
+ /* Unknown -- two bytes = 0x0001 */
+ if (aim_gettlv(list2, 0x000a, 1))
+ ;
+
+ /* Unknown -- no value */
+ if (aim_gettlv(list2, 0x000f, 1))
+ ;
+
+ faimdprintf(sess, 1, "rend: directIM request from %s (%s)\n", userinfo->sn, args->info.imimage.ip);
+
+ /*
+ * XXX: there are a couple of different request packets for
+ * different things
+ */
+
+ if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
+ ret = userfunc(sess, rx, 0x0002, userinfo, args);
+
+ return ret;
+}
+
/* XXX Ugh. I think its obvious. */
static int incomingim_ch2(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, fu16_t channel, struct aim_userinfo_s *userinfo, aim_tlvlist_t *tlvlist, fu8_t *cookie)
{
cookie2 = aimbs_getraw(&bbs, 8);
if (memcmp(cookie, cookie2, 8) != 0)
faimdprintf(sess, 0, "rend: warning cookies don't match!\n");
+ memcpy(args.cookie, cookie2, 8);
free(cookie2);
/*
*/
list2 = aim_readtlvchain(&bbs);
+#if 0 /* this should be in the per-type blocks */
if (!list2 || ((args.reqclass != AIM_CAPS_IMIMAGE) && !(aim_gettlv(list2, 0x2711, 1)))) {
aim_msgcookie_t *cook;
int type;
return 1;
}
+#endif
/*
* The rest of the handling depends on what type it is.
*/
if (args.reqclass & AIM_CAPS_BUDDYICON) {
- aim_tlv_t *miscinfo;
- aim_bstream_t tbs;
- miscinfo = aim_gettlv(list2, 0x2711, 1);
- aim_bstream_init(&tbs, miscinfo->value, miscinfo->length);
-
- args.info.icon.checksum = aimbs_get32(&tbs);
- args.info.icon.length = aimbs_get32(&tbs);
- args.info.icon.timestamp = aimbs_get32(&tbs);
- args.info.icon.icon = aimbs_getraw(&tbs, 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);
+ ret = incomingim_ch2_buddyicon(sess, mod, rx, snac, userinfo, &args, list2);
} else if (args.reqclass & AIM_CAPS_VOICE) {
aim_msgcookie_t *cachedcook;
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)) {
- 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);
+ ret = incomingim_ch2_imimage(sess, mod, rx, snac, userinfo, &args, list2);
} else if (args.reqclass & AIM_CAPS_CHAT) {
aim_tlv_t *miscinfo;