+ else if (channel == 0x0002)
+ {
+ struct aim_tlv_t *block1;
+ struct aim_tlvlist_t *list2;
+ struct aim_tlv_t *tmptlv;
+ unsigned short reqclass = 0;
+ unsigned short status = 0;
+
+ /*
+ * There's another block of TLVs embedded in the type 5 here.
+ */
+ block1 = aim_gettlv(tlvlist, 0x0005, 1);
+ if (!block1) {
+ printf("faim: no tlv 0x0005 in rendezvous transaction!\n");
+ aim_freetlvchain(&tlvlist);
+ return 1; /* major problem */
+ }
+
+ /*
+ * First two bytes represent the status of the connection.
+ *
+ * 0 is a request, 2 is an accept
+ */
+ status = aimutil_get16(block1->value+0);
+
+ /*
+ * Next comes the cookie. Should match the ICBM cookie.
+ */
+ if (memcmp(block1->value+2, cookie, 8) != 0)
+ printf("faim: rend: warning cookies don't match!\n");
+
+ /*
+ * The next 16bytes are a capability block so we can
+ * identify what type of rendezvous this is.
+ *
+ * Thanks to Eric Warmenhoven <warmenhoven@linux.com> (of GAIM)
+ * for pointing some of this out to me. In fact, a lot of
+ * the client-to-client info comes from the work of the GAIM
+ * developers. Thanks!
+ *
+ * Read off one capability string and we should have it ID'd.
+ *
+ */
+ reqclass = aim_getcap(block1->value+2+8, 0x10);
+ if (reqclass == 0x0000) {
+ printf("faim: rend: no ID block\n");
+ aim_freetlvchain(&tlvlist);
+ return 1;
+ }
+
+ /*
+ * What follows may be TLVs or nothing, depending on the
+ * purpose of the message.
+ *
+ * Ack packets for instance have nothing more to them.
+ */
+ list2 = aim_readtlvchain(block1->value+2+8+16, block1->length-2-8-16);
+
+ if (!list2 || ((reqclass != AIM_CAPS_IMIMAGE) && !(aim_gettlv(list2, 0x2711, 1)))) {
+ struct aim_msgcookie_t *cook;
+ int type;
+
+ type = aim_msgcookie_gettype(reqclass); /* XXX: fix this shitty code */
+
+ if ((cook = aim_uncachecookie(sess, cookie, type)) == NULL) {
+ printf("faim: non-data rendezvous thats not in cache!\n");
+ aim_freetlvchain(&list2);
+ aim_freetlvchain(&tlvlist);
+ return 1;
+ }
+
+ if (cook->type == AIM_CAPS_SENDFILE) {
+ struct aim_filetransfer_priv *ft;
+
+ if (cook->data) {
+ struct aim_tlv_t *errortlv;
+ int errorcode = -1;
+
+ ft = (struct aim_filetransfer_priv *)cook->data;
+
+ if ((errortlv = aim_gettlv(list2, 0x000b, 1))) {
+ errorcode = aimutil_get16(errortlv->value);
+ }
+ if (errorcode) {
+ printf("faim: transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode);
+ } else if (status == 0x0002) { /* connection accepted */
+ printf("faim: transfer from %s (%s) for %s accepted\n", ft->sn, ft->ip, ft->fh.name);
+ }
+ free(cook->data);
+ } else {
+ printf("faim: not data attached to file transfer\n");
+ }
+ } else if (cook->type == AIM_CAPS_VOICE) {
+ printf("faim: voice request cancelled\n");
+ } else {
+ printf("faim: unknown cookie cache type %d\n", cook->type);
+ }
+
+ free(cook);
+ if (list2)
+ aim_freetlvchain(&list2);
+ aim_freetlvchain(&tlvlist);
+ return 1;
+ }
+
+ /*
+ * The rest of the handling depends on what type it is.
+ */
+ if (reqclass & AIM_CAPS_BUDDYICON) {
+
+ /*
+ * Call client.
+ */
+ userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
+ if (userfunc || (i = 0))
+ i = userfunc(sess,
+ command,
+ channel,
+ reqclass,
+ &userinfo);
+
+ } else if (reqclass & AIM_CAPS_VOICE) {
+ struct aim_msgcookie_t *cachedcook;
+
+ printf("faim: rend: voice!\n");
+
+ if(!(cachedcook = (struct aim_msgcookie_t*)calloc(1, sizeof(struct aim_msgcookie_t))))
+ return 1;
+
+ memcpy(cachedcook->cookie, cookie, 8);
+ cachedcook->type = AIM_COOKIETYPE_OFTVOICE;
+ cachedcook->data = NULL;
+
+ if (aim_cachecookie(sess, cachedcook) != 0)
+ printf("faim: ERROR caching message cookie\n");
+
+ /* XXX: implement all this */
+
+ /*
+ * Call client.
+ */
+ userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
+ if (userfunc || (i = 0)) {
+ i = userfunc(sess, command, channel, reqclass, &userinfo);
+ }
+ } else if ((reqclass & AIM_CAPS_IMIMAGE) || (reqclass & AIM_CAPS_BUDDYICON)) {
+ 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, sizeof(ip)-1, "%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)*/);
+ }
+
+ printf("faim: rend: directIM request from %s (%s)\n",
+ userinfo.sn,
+ ip);
+
+ /* XXX: there are a couple of different request packets for
+ * different things */
+
+ priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv));
+ memcpy(priv->ip, ip, sizeof(priv->ip));
+ memcpy(priv->sn, userinfo.sn, sizeof(priv->sn));
+ memcpy(priv->cookie, cookie, sizeof(priv->cookie));
+
+ /*
+ * Call client.
+ */
+ userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
+ if (userfunc || (i = 0))
+ i = userfunc(sess,
+ command,
+ channel,
+ reqclass,
+ &userinfo, priv);
+
+ } else if (reqclass & AIM_CAPS_CHAT) {
+ struct aim_tlv_t *miscinfo;
+ struct aim_chat_roominfo roominfo;
+ char *msg=NULL,*encoding=NULL,*lang=NULL;
+
+ miscinfo = aim_gettlv(list2, 0x2711, 1);
+ aim_chat_readroominfo(miscinfo->value, &roominfo);
+
+ if (aim_gettlv(list2, 0x000c, 1))
+ msg = aim_gettlv_str(list2, 0x000c, 1);
+
+ if (aim_gettlv(list2, 0x000d, 1))
+ encoding = aim_gettlv_str(list2, 0x000d, 1);
+
+ if (aim_gettlv(list2, 0x000e, 1))
+ lang = aim_gettlv_str(list2, 0x000e, 1);
+
+ /*
+ * Call client.
+ */
+ userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
+ if (userfunc || (i = 0))
+ i = userfunc(sess,
+ command,
+ channel,
+ reqclass,
+ &userinfo,
+ &roominfo,
+ msg,
+ encoding?encoding+1:NULL,
+ lang?lang+1:NULL);
+ free(roominfo.name);
+ free(msg);
+ free(encoding);
+ free(lang);
+ } else if (reqclass & AIM_CAPS_GETFILE) {
+ char ip[30];
+ char *desc = NULL;
+ struct aim_msgcookie_t *cachedcook;
+ struct aim_filetransfer_priv *ft;
+ struct aim_tlv_t *miscinfo;
+ struct aim_conn_t *newconn;
+
+ if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t))))
+ return 0;
+
+ memset(ip, 0, sizeof(ip));
+
+ if (!(miscinfo = aim_gettlv(list2, 0x2711, 1))) {
+ free(cachedcook);
+ return 0;
+ }
+
+ if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
+ struct aim_tlv_t *iptlv, *porttlv;
+
+ if (!(iptlv = aim_gettlv(list2, 0x0003, 1)) || !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
+ free(cachedcook);
+ return 0;
+ }
+
+ snprintf(ip, sizeof(ip)-1, "%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));
+ }
+
+ printf("faim: rend: file get request from %s (%s)\n", userinfo.sn, ip);
+
+#if 0 /* XXX finish this */
+ newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, ip);
+ if (!newconn || (newconn->fd == -1)) {
+ printf("could not connect to %s\n", ip);
+ perror("aim_newconn");
+ aim_conn_kill(sess, &newconn);
+ } else {
+ struct aim_filetransfer_priv *priv;
+ priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv));
+ memcpy(priv->cookie, cookie, 8);
+ strncpy(priv->sn, userinfo.sn, MAXSNLEN);
+ newconn->priv = priv;
+ printf("faim: connected to peer (fd = %d)\n", newconn->fd);
+ }
+
+ memcpy(cachedcook->cookie, cookie, 8);
+
+ ft = malloc(sizeof(struct aim_filetransfer_priv));
+ ft->state = 1;
+ strncpy(ft->sn, userinfo.sn, sizeof(ft->sn));
+ strncpy(ft->ip, ip, sizeof(ft->ip));
+#if 0
+ strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name));
+#endif
+ cachedcook->type = AIM_COOKIETYPE_OFTGET;
+ cachedcook->data = ft;