From: Eric W. <war...@us...> - 2001-11-14 19:21:23
|
Update of /cvsroot/gaim/gaim/src/protocols/oscar In directory usw-pr-cvs1:/tmp/cvs-serv2408/src/protocols/oscar Modified Files: aim.h aim_internal.h ft.c im.c oscar.c Log Message: these are changes i made, all by myself. aren't you impressed. mid's going to change around im.c here in a minute anyway. Index: aim.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/oscar/aim.h,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- aim.h 2001/11/10 08:02:39 1.18 +++ aim.h 2001/11/14 19:21:20 1.19 @@ -801,8 +801,10 @@ faim_export fu16_t aim_iconsum(const fu8_t *buf, int buflen); faim_export int aim_send_im_direct(aim_session_t *, aim_conn_t *, const char *msg); faim_export const char *aim_directim_getsn(aim_conn_t *conn); -faim_export aim_conn_t *aim_directim_initiate(aim_session_t *, aim_conn_t *, const char *destsn); +faim_export aim_conn_t *aim_directim_initiate(aim_session_t *, const char *destsn); faim_export aim_conn_t *aim_directim_connect(aim_session_t *, const char *sn, const char *addr, const fu8_t *cookie); + +faim_export aim_conn_t *aim_sendfile_initiate(aim_session_t *, const char *destsn, const char *filename, fu16_t numfiles, fu32_t totsize); faim_export aim_conn_t *aim_getfile_initiate(aim_session_t *sess, aim_conn_t *conn, const char *destsn); faim_export int aim_oft_getfile_request(aim_session_t *sess, aim_conn_t *conn, const char *name, int size); Index: aim_internal.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/oscar/aim_internal.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- aim_internal.h 2001/11/10 08:02:39 1.8 +++ aim_internal.h 2001/11/14 19:21:20 1.9 @@ -203,6 +203,8 @@ faim_internal void faimdprintf(aim_session_t *sess, int dlevel, const char *format, ...); +faim_internal int aim_request_directim(aim_session_t *sess, const char *destsn, fu8_t *ip, fu16_t port, fu8_t *ckret); +faim_internal int aim_request_sendfile(aim_session_t *sess, const char *sn, const char *filename, fu16_t numfiles, fu32_t totsize, fu8_t *ip, fu16_t port, fu8_t *ckret); faim_internal void aim_conn_close_rend(aim_session_t *sess, aim_conn_t *conn); faim_internal void aim_conn_kill_rend(aim_session_t *sess, aim_conn_t *conn); Index: ft.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/oscar/ft.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- ft.c 2001/11/13 06:30:37 1.7 +++ ft.c 2001/11/14 19:21:20 1.8 @@ -190,10 +190,6 @@ return 0; } -/* XXX: give the client author the responsibility of setting up a - * listener, then we no longer have a libfaim problem with broken - * solaris *innocent smile* -jbm */ - static int getlocalip(fu8_t *ip) { struct hostent *hptr; @@ -213,88 +209,75 @@ return 0; } -/* XXX this should probably go in im.c */ -static int aim_request_directim(aim_session_t *sess, aim_conn_t *conn, const char *destsn, fu8_t *ip, fu16_t port, fu8_t *ckret) -{ +/** + * aim_directim_intitiate - For those times when we want to open up the directim channel ourselves. + * @sess: your session, + * @conn: the BOS conn, + * @priv: a dummy priv value (we'll let it get filled in later) (if you pass a %NULL, we alloc one) + * @destsn: the SN to connect to. + * + */ +faim_export aim_conn_t *aim_directim_initiate(aim_session_t *sess, const char *destsn) +{ + aim_conn_t *newconn; + aim_msgcookie_t *cookie; + struct aim_directim_intdata *priv; + int listenfd; + fu16_t port = 4443; + fu8_t localip[4]; fu8_t ck[8]; - aim_frame_t *fr; - aim_snacid_t snacid; - aim_tlvlist_t *tl = NULL, *itl = NULL; - int hdrlen, i; - fu8_t *hdr; - aim_bstream_t hdrbs; - if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 256+strlen(destsn)))) - return -ENOMEM; - - snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); - aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); - - /* - * Generate a random message cookie - * - * This cookie needs to be alphanumeric and NULL-terminated to be - * TOC-compatible. - * - * XXX have I mentioned these should be generated in msgcookie.c? - * - */ - for (i = 0; i < 7; i++) - ck[i] = 0x30 + ((fu8_t) rand() % 10); - ck[7] = '\0'; - - if (ckret) - memcpy(ckret, ck, 8); - - /* Cookie */ - aimbs_putraw(&fr->data, ck, 8); + if (getlocalip(localip) == -1) + return NULL; - /* Channel */ - aimbs_put16(&fr->data, 0x0002); + if ((listenfd = listenestablish(port)) == -1) + return NULL; - /* Destination SN */ - aimbs_put8(&fr->data, strlen(destsn)); - aimbs_putraw(&fr->data, destsn, strlen(destsn)); + aim_request_directim(sess, destsn, localip, port, ck); - aim_addtlvtochain_noval(&tl, 0x0003); + cookie = (aim_msgcookie_t *)calloc(1, sizeof(aim_msgcookie_t)); + memcpy(cookie->cookie, ck, 8); + cookie->type = AIM_COOKIETYPE_OFTIM; - hdrlen = 2+8+16+6+8+6+4; - hdr = malloc(hdrlen); - aim_bstream_init(&hdrbs, hdr, hdrlen); + /* this one is for the cookie */ + priv = (struct aim_directim_intdata *)calloc(1, sizeof(struct aim_directim_intdata)); - aimbs_put16(&hdrbs, 0x0000); - aimbs_putraw(&hdrbs, ck, 8); - aim_putcap(&hdrbs, AIM_CAPS_IMIMAGE); + memcpy(priv->cookie, ck, 8); + strncpy(priv->sn, destsn, sizeof(priv->sn)); + cookie->data = priv; + aim_cachecookie(sess, cookie); - aim_addtlvtochain16(&itl, 0x000a, 0x0001); - aim_addtlvtochain_raw(&itl, 0x0003, 4, ip); - aim_addtlvtochain16(&itl, 0x0005, port); - aim_addtlvtochain_noval(&itl, 0x000f); - - aim_writetlvchain(&hdrbs, &itl); + /* XXX switch to aim_cloneconn()? */ + if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL))) { + close(listenfd); + return NULL; + } - aim_addtlvtochain_raw(&tl, 0x0005, aim_bstream_curpos(&hdrbs), hdr); + /* this one is for the conn */ + priv = (struct aim_directim_intdata *)calloc(1, sizeof(struct aim_directim_intdata)); - aim_writetlvchain(&fr->data, &tl); + memcpy(priv->cookie, ck, 8); + strncpy(priv->sn, destsn, sizeof(priv->sn)); - free(hdr); - aim_freetlvchain(&itl); - aim_freetlvchain(&tl); + newconn->fd = listenfd; + newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM; + newconn->internal = priv; + newconn->lastactivity = time(NULL); - aim_tx_enqueue(sess, fr); + faimdprintf(sess, 2,"faim: listening (fd = %d, unconnected)\n", newconn->fd); - return 0; + return newconn; } /** - * aim_directim_intitiate - For those times when we want to open up the directim channel ourselves. + * aim_sendfile_intitiate - For those times when we want to send the file ourselves. * @sess: your session, * @conn: the BOS conn, - * @priv: a dummy priv value (we'll let it get filled in later) (if you pass a %NULL, we alloc one) * @destsn: the SN to connect to. + * @filename: the name of the files you want to send * */ -faim_export aim_conn_t *aim_directim_initiate(aim_session_t *sess, aim_conn_t *conn, const char *destsn) +faim_export aim_conn_t *aim_sendfile_initiate(aim_session_t *sess, const char *destsn, const char *filename, fu16_t numfiles, fu32_t totsize) { aim_conn_t *newconn; aim_msgcookie_t *cookie; @@ -310,7 +293,7 @@ if ((listenfd = listenestablish(port)) == -1) return NULL; - aim_request_directim(sess, conn, destsn, localip, port, ck); + aim_request_sendfile(sess, destsn, filename, numfiles, totsize, localip, port, ck); cookie = (aim_msgcookie_t *)calloc(1, sizeof(aim_msgcookie_t)); memcpy(cookie->cookie, ck, 8); @@ -337,14 +320,14 @@ strncpy(priv->sn, destsn, sizeof(priv->sn)); newconn->fd = listenfd; - newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM; + newconn->subtype = AIM_CONN_SUBTYPE_OFT_SENDFILE; newconn->internal = priv; newconn->lastactivity = time(NULL); faimdprintf(sess, 2,"faim: listening (fd = %d, unconnected)\n", newconn->fd); return newconn; -} +} #if 0 /** @@ -776,6 +759,9 @@ * * you need to call accept() when it's connected. returns your fd * + * XXX: give the client author the responsibility of setting up a + * listener, then we no longer have a libfaim problem with broken + * solaris *innocent smile* -jbm */ static int listenestablish(fu16_t portnum) { Index: im.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/oscar/im.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- im.c 2001/11/10 01:48:17 1.15 +++ im.c 2001/11/14 19:21:20 1.16 @@ -449,6 +449,174 @@ return 0; } +faim_internal int aim_request_directim(aim_session_t *sess, const char *destsn, fu8_t *ip, fu16_t port, fu8_t *ckret) +{ + aim_conn_t *conn; + fu8_t ck[8]; + aim_frame_t *fr; + aim_snacid_t snacid; + aim_tlvlist_t *tl = NULL, *itl = NULL; + int hdrlen, i; + fu8_t *hdr; + aim_bstream_t hdrbs; + + if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004))) + return -EINVAL; + + if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 256+strlen(destsn)))) + return -ENOMEM; + + snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); + aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); + + /* + * Generate a random message cookie + * + * This cookie needs to be alphanumeric and NULL-terminated to be + * TOC-compatible. + * + * XXX have I mentioned these should be generated in msgcookie.c? + * + */ + for (i = 0; i < 7; i++) + ck[i] = 0x30 + ((fu8_t) rand() % 10); + ck[7] = '\0'; + + if (ckret) + memcpy(ckret, ck, 8); + + /* Cookie */ + aimbs_putraw(&fr->data, ck, 8); + + /* Channel */ + aimbs_put16(&fr->data, 0x0002); + + /* Destination SN */ + aimbs_put8(&fr->data, strlen(destsn)); + aimbs_putraw(&fr->data, destsn, strlen(destsn)); + + aim_addtlvtochain_noval(&tl, 0x0003); + + hdrlen = 2+8+16+6+8+6+4; + hdr = malloc(hdrlen); + aim_bstream_init(&hdrbs, hdr, hdrlen); + + aimbs_put16(&hdrbs, 0x0000); + aimbs_putraw(&hdrbs, ck, 8); + aim_putcap(&hdrbs, AIM_CAPS_IMIMAGE); + + aim_addtlvtochain16(&itl, 0x000a, 0x0001); + aim_addtlvtochain_raw(&itl, 0x0003, 4, ip); + aim_addtlvtochain16(&itl, 0x0005, port); + aim_addtlvtochain_noval(&itl, 0x000f); + + aim_writetlvchain(&hdrbs, &itl); + + aim_addtlvtochain_raw(&tl, 0x0005, aim_bstream_curpos(&hdrbs), hdr); + + aim_writetlvchain(&fr->data, &tl); + + free(hdr); + aim_freetlvchain(&itl); + aim_freetlvchain(&tl); + + aim_tx_enqueue(sess, fr); + + return 0; +} + +faim_internal int aim_request_sendfile(aim_session_t *sess, const char *sn, const char *filename, fu16_t numfiles, fu32_t totsize, fu8_t *ip, fu16_t port, fu8_t *ckret) +{ + aim_conn_t *conn; + int i; + fu8_t ck[8]; + aim_frame_t *fr; + aim_snacid_t snacid; + + if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004))) + return -EINVAL; + + if (!sn || !filename) + return -EINVAL; + + if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sn)+2+2+2+8+16+6+8+6+4+2+2+2+2+4+strlen(filename)+4))) + return -ENOMEM; + + snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); + aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); + + for (i = 0; i < 7; i++) + aimutil_put8(ck+i, 0x30 + ((fu8_t) rand() % 10)); + ck[7] = '\0'; + + if (ckret) + memcpy(ckret, ck, 8); + + /* + * Cookie + */ + aimbs_putraw(&fr->data, ck, 8); + + /* + * Channel (2) + */ + aimbs_put16(&fr->data, 0x0002); + + /* + * Dest sn + */ + aimbs_put8(&fr->data, strlen(sn)); + aimbs_putraw(&fr->data, sn, strlen(sn)); + + /* + * TLV t(0005) + * + * Encompasses everything below. Gee. + */ + aimbs_put16(&fr->data, 0x0005); + aimbs_put16(&fr->data, 2+8+16+6+8+6+4+2+2+2+2+4+strlen(filename)+4); + + aimbs_put16(&fr->data, 0x0000); + aimbs_putraw(&fr->data, ck, 8); + aim_putcap(&fr->data, AIM_CAPS_SENDFILE); + + /* TLV t(000a) */ + aimbs_put16(&fr->data, 0x000a); + aimbs_put16(&fr->data, 0x0002); + aimbs_put16(&fr->data, 0x0001); + + /* TLV t(0003) (IP) */ + aimbs_put16(&fr->data, 0x0003); + aimbs_put16(&fr->data, 0x0004); + aimbs_putraw(&fr->data, ip, 4); + + /* TLV t(0005) (port) */ + aimbs_put16(&fr->data, 0x0005); + aimbs_put16(&fr->data, 0x0002); + aimbs_put16(&fr->data, port); + + /* TLV t(000f) */ + aimbs_put16(&fr->data, 0x000f); + aimbs_put16(&fr->data, 0x0000); + + /* TLV t(2711) */ + aimbs_put16(&fr->data, 0x2711); + aimbs_put16(&fr->data, 2+2+4+strlen(filename)+4); + + /* ? */ + aimbs_put16(&fr->data, 0x0001); + aimbs_put16(&fr->data, numfiles); + aimbs_put32(&fr->data, totsize); + aimbs_putraw(&fr->data, filename, strlen(filename)); + + /* ? */ + aimbs_put32(&fr->data, 0x00000000); + + aim_tx_enqueue(sess, fr); + + return 0; +} + static int outgoingim(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) { int i, ret = 0; Index: oscar.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/oscar/oscar.c,v retrieving revision 1.64 retrieving revision 1.65 diff -u -d -r1.64 -r1.65 --- oscar.c 2001/11/13 06:48:34 1.64 +++ oscar.c 2001/11/14 19:21:20 1.65 @@ -2588,7 +2588,7 @@ dim->gc = gc; g_snprintf(dim->name, sizeof dim->name, "%s", data->who); - dim->conn = aim_directim_initiate(od->sess, od->conn, data->who); + dim->conn = aim_directim_initiate(od->sess, data->who); if (dim->conn != NULL) { od->direct_ims = g_slist_append(od->direct_ims, dim); dim->watcher = gaim_input_add(dim->conn->fd, GAIM_INPUT_READ, |