diff options
Diffstat (limited to 'protocols/oscar/im.c')
-rw-r--r-- | protocols/oscar/im.c | 586 |
1 files changed, 0 insertions, 586 deletions
diff --git a/protocols/oscar/im.c b/protocols/oscar/im.c index a01a2614..05e06e91 100644 --- a/protocols/oscar/im.c +++ b/protocols/oscar/im.c @@ -23,22 +23,6 @@ #include "im.h" #include "info.h" -/* This should be endian-safe now... but who knows... */ -guint16 aim_iconsum(const guint8 *buf, int buflen) -{ - guint32 sum; - int i; - - for (i = 0, sum = 0; i + 1 < buflen; i += 2) - sum += (buf[i+1] << 8) + buf[i]; - if (i < buflen) - sum += buf[i]; - - sum = ((sum & 0xffff0000) >> 16) + (sum & 0x0000ffff); - - return (guint16)sum; -} - /* * Send an ICBM (instant message). * @@ -305,483 +289,6 @@ int aim_send_im(aim_session_t *sess, const char *destsn, guint16 flags, const ch return aim_send_im_ext(sess, &args); } -/* - * This is also performance sensitive. (If you can believe it...) - * - */ -int aim_send_icon(aim_session_t *sess, const char *sn, const guint8 *icon, int iconlen, time_t stamp, guint16 iconsum) -{ - aim_conn_t *conn; - int i; - guint8 ck[8]; - aim_frame_t *fr; - aim_snacid_t snacid; - - if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004))) - return -EINVAL; - - if (!sn || !icon || (iconlen <= 0) || (iconlen >= MAXICONLEN)) - return -EINVAL; - - for (i = 0; i < 8; i++) - aimutil_put8(ck+i, (guint8) rand()); - - if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sn)+2+2+2+8+16+2+2+2+2+2+2+2+4+4+4+iconlen+strlen(AIM_ICONIDENT)+2+2))) - return -ENOMEM; - - snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); - aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); - - /* - * 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, (guint8 *)sn, strlen(sn)); - - /* - * TLV t(0005) - * - * Encompasses everything below. - */ - aimbs_put16(&fr->data, 0x0005); - aimbs_put16(&fr->data, 2+8+16+6+4+4+iconlen+4+4+4+strlen(AIM_ICONIDENT)); - - aimbs_put16(&fr->data, 0x0000); - aimbs_putraw(&fr->data, ck, 8); - aim_putcap(&fr->data, AIM_CAPS_BUDDYICON); - - /* TLV t(000a) */ - aimbs_put16(&fr->data, 0x000a); - aimbs_put16(&fr->data, 0x0002); - aimbs_put16(&fr->data, 0x0001); - - /* 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, 4+4+4+iconlen+strlen(AIM_ICONIDENT)); - aimbs_put16(&fr->data, 0x0000); - aimbs_put16(&fr->data, iconsum); - aimbs_put32(&fr->data, iconlen); - aimbs_put32(&fr->data, stamp); - aimbs_putraw(&fr->data, icon, iconlen); - aimbs_putraw(&fr->data, (guint8 *)AIM_ICONIDENT, strlen(AIM_ICONIDENT)); - - /* TLV t(0003) */ - aimbs_put16(&fr->data, 0x0003); - aimbs_put16(&fr->data, 0x0000); - - aim_tx_enqueue(sess, fr); - - return 0; -} - -/* - * This only works for ICQ 2001b (thats 2001 not 2000). Better, only - * send it to clients advertising the RTF capability. In fact, if you send - * it to a client that doesn't support that capability, the server will gladly - * bounce it back to you. - * - * You'd think this would be in icq.c, but, well, I'm trying to stick with - * the one-group-per-file scheme as much as possible. This could easily - * be an exception, since Rendezvous IMs are external of the Oscar core, - * and therefore are undefined. Really I just need to think of a good way to - * make an interface similar to what AOL actually uses. But I'm not using COM. - * - */ -int aim_send_rtfmsg(aim_session_t *sess, struct aim_sendrtfmsg_args *args) -{ - const char rtfcap[] = {"{97B12751-243C-4334-AD22-D6ABF73F1492}"}; /* AIM_CAPS_ICQRTF capability in string form */ - aim_conn_t *conn; - int i; - guint8 ck[8]; - aim_frame_t *fr; - aim_snacid_t snacid; - int servdatalen; - - if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004))) - return -EINVAL; - - if (!args || !args->destsn || !args->rtfmsg) - return -EINVAL; - - servdatalen = 2+2+16+2+4+1+2 + 2+2+4+4+4 + 2+4+2+strlen(args->rtfmsg)+1 + 4+4+4+strlen(rtfcap)+1; - - for (i = 0; i < 8; i++) - aimutil_put8(ck+i, (guint8) rand()); - - if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+128+servdatalen))) - return -ENOMEM; - - snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); - aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); - - /* - * Cookie - */ - aimbs_putraw(&fr->data, ck, 8); - - /* - * Channel (2) - */ - aimbs_put16(&fr->data, 0x0002); - - /* - * Dest sn - */ - aimbs_put8(&fr->data, strlen(args->destsn)); - aimbs_putraw(&fr->data, (guint8 *)args->destsn, strlen(args->destsn)); - - /* - * TLV t(0005) - * - * Encompasses everything below. - */ - aimbs_put16(&fr->data, 0x0005); - aimbs_put16(&fr->data, 2+8+16 + 2+2+2 + 2+2 + 2+2+servdatalen); - - aimbs_put16(&fr->data, 0x0000); - aimbs_putraw(&fr->data, ck, 8); - aim_putcap(&fr->data, AIM_CAPS_ICQSERVERRELAY); - - /* - * t(000a) l(0002) v(0001) - */ - aimbs_put16(&fr->data, 0x000a); - aimbs_put16(&fr->data, 0x0002); - aimbs_put16(&fr->data, 0x0001); - - /* - * t(000f) l(0000) v() - */ - aimbs_put16(&fr->data, 0x000f); - aimbs_put16(&fr->data, 0x0000); - - /* - * Service Data TLV - */ - aimbs_put16(&fr->data, 0x2711); - aimbs_put16(&fr->data, servdatalen); - - aimbs_putle16(&fr->data, 11 + 16 /* 11 + (sizeof CLSID) */); - aimbs_putle16(&fr->data, 9); - aim_putcap(&fr->data, AIM_CAPS_EMPTY); - aimbs_putle16(&fr->data, 0); - aimbs_putle32(&fr->data, 0); - aimbs_putle8(&fr->data, 0); - aimbs_putle16(&fr->data, 0x03ea); /* trid1 */ - - aimbs_putle16(&fr->data, 14); - aimbs_putle16(&fr->data, 0x03eb); /* trid2 */ - aimbs_putle32(&fr->data, 0); - aimbs_putle32(&fr->data, 0); - aimbs_putle32(&fr->data, 0); - - aimbs_putle16(&fr->data, 0x0001); - aimbs_putle32(&fr->data, 0); - aimbs_putle16(&fr->data, strlen(args->rtfmsg)+1); - aimbs_putraw(&fr->data, (guint8 *)args->rtfmsg, strlen(args->rtfmsg)+1); - - aimbs_putle32(&fr->data, args->fgcolor); - aimbs_putle32(&fr->data, args->bgcolor); - aimbs_putle32(&fr->data, strlen(rtfcap)+1); - aimbs_putraw(&fr->data, (guint8 *)rtfcap, strlen(rtfcap)+1); - - aim_tx_enqueue(sess, fr); - - return 0; -} - -int aim_request_directim(aim_session_t *sess, const char *destsn, guint8 *ip, guint16 port, guint8 *ckret) -{ - aim_conn_t *conn; - guint8 ck[8]; - aim_frame_t *fr; - aim_snacid_t snacid; - aim_tlvlist_t *tl = NULL, *itl = NULL; - int hdrlen, i; - guint8 *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 + ((guint8) 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, (guint8 *)destsn, strlen(destsn)); - - aim_addtlvtochain_noval(&tl, 0x0003); - - hdrlen = 2+8+16+6+8+6+4; - hdr = g_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); - - g_free(hdr); - aim_freetlvchain(&itl); - aim_freetlvchain(&tl); - - aim_tx_enqueue(sess, fr); - - return 0; -} - -int aim_request_sendfile(aim_session_t *sess, const char *sn, const char *filename, guint16 numfiles, guint32 totsize, guint8 *ip, guint16 port, guint8 *ckret) -{ - aim_conn_t *conn; - int i; - guint8 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 + ((guint8) 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, (guint8 *)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, (guint8 *)filename, strlen(filename)); - - /* ? */ - aimbs_put32(&fr->data, 0x00000000); - - aim_tx_enqueue(sess, fr); - - return 0; -} - -/** - * Request the status message of the given ICQ user. - * - * @param sess The oscar session. - * @param sn The UIN of the user of whom you wish to request info. - * @param type The type of info you wish to request. This should be the current - * state of the user, as one of the AIM_ICQ_STATE_* defines. - * @return Return 0 if no errors, otherwise return the error number. - */ -int aim_send_im_ch2_geticqmessage(aim_session_t *sess, const char *sn, int type) -{ - aim_conn_t *conn; - int i; - guint8 ck[8]; - aim_frame_t *fr; - aim_snacid_t snacid; - - if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004)) || !sn) - return -EINVAL; - - for (i = 0; i < 8; i++) - aimutil_put8(ck+i, (guint8) rand()); - - if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sn) + 4+0x5e + 4))) - return -ENOMEM; - - snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); - aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); - - /* 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, (guint8 *)sn, strlen(sn)); - - /* TLV t(0005) - Encompasses almost everything below. */ - aimbs_put16(&fr->data, 0x0005); /* T */ - aimbs_put16(&fr->data, 0x005e); /* L */ - { /* V */ - aimbs_put16(&fr->data, 0x0000); - - /* Cookie */ - aimbs_putraw(&fr->data, ck, 8); - - /* Put the 16 byte server relay capability */ - aim_putcap(&fr->data, AIM_CAPS_ICQSERVERRELAY); - - /* TLV t(000a) */ - aimbs_put16(&fr->data, 0x000a); - aimbs_put16(&fr->data, 0x0002); - aimbs_put16(&fr->data, 0x0001); - - /* 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, 0x0036); - { /* V */ - aimbs_putle16(&fr->data, 0x001b); /* L */ - aimbs_putle16(&fr->data, 0x0008); /* AAA - Protocol version */ - aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ - aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ - aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ - aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ - aimbs_putle16(&fr->data, 0x0000); /* Unknown */ - aimbs_putle16(&fr->data, 0x0003); /* Client features? */ - aimbs_putle16(&fr->data, 0x0000); /* Unknown */ - aimbs_putle8(&fr->data, 0x00); /* Unkizown */ - aimbs_putle16(&fr->data, 0xffff); /* Sequence number? XXX - This should decrement by 1 with each request */ - - aimbs_putle16(&fr->data, 0x000e); /* L */ - aimbs_putle16(&fr->data, 0xffff); /* Sequence number? XXX - This should decrement by 1 with each request */ - aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ - aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ - aimbs_putle32(&fr->data, 0x00000000); /* Unknown */ - - /* The type of status message being requested */ - if (type & AIM_ICQ_STATE_CHAT) - aimbs_putle16(&fr->data, 0x03ec); - else if(type & AIM_ICQ_STATE_DND) - aimbs_putle16(&fr->data, 0x03eb); - else if(type & AIM_ICQ_STATE_OUT) - aimbs_putle16(&fr->data, 0x03ea); - else if(type & AIM_ICQ_STATE_BUSY) - aimbs_putle16(&fr->data, 0x03e9); - else if(type & AIM_ICQ_STATE_AWAY) - aimbs_putle16(&fr->data, 0x03e8); - - aimbs_putle16(&fr->data, 0x0000); /* Status? */ - aimbs_putle16(&fr->data, 0x0001); /* Priority of this message? */ - aimbs_putle16(&fr->data, 0x0001); /* L? */ - aimbs_putle8(&fr->data, 0x00); /* Null termination? */ - } /* End TLV t(2711) */ - } /* End TLV t(0005) */ - - /* TLV t(0003) */ - aimbs_put16(&fr->data, 0x0003); - aimbs_put16(&fr->data, 0x0000); - - aim_tx_enqueue(sess, fr); - - return 0; -} - /** * answers status message requests * @param sess the oscar session @@ -991,61 +498,6 @@ static int mpmsg_addsection(aim_session_t *sess, aim_mpmsg_t *mpm, guint16 chars return 0; } -int aim_mpmsg_addraw(aim_session_t *sess, aim_mpmsg_t *mpm, guint16 charset, guint16 charsubset, const guint8 *data, guint16 datalen) -{ - guint8 *dup; - - if (!(dup = g_malloc(datalen))) - return -1; - memcpy(dup, data, datalen); - - if (mpmsg_addsection(sess, mpm, charset, charsubset, dup, datalen) == -1) { - g_free(dup); - return -1; - } - - return 0; -} - -/* XXX should provide a way of saying ISO-8859-1 specifically */ -int aim_mpmsg_addascii(aim_session_t *sess, aim_mpmsg_t *mpm, const char *ascii) -{ - char *dup; - - if (!(dup = g_strdup(ascii))) - return -1; - - if (mpmsg_addsection(sess, mpm, 0x0000, 0x0000, (guint8 *)dup, (guint16) strlen(ascii)) == -1) { - g_free(dup); - return -1; - } - - return 0; -} - -int aim_mpmsg_addunicode(aim_session_t *sess, aim_mpmsg_t *mpm, const guint16 *unicode, guint16 unicodelen) -{ - guint8 *buf; - aim_bstream_t bs; - int i; - - if (!(buf = g_malloc(unicodelen * 2))) - return -1; - - aim_bstream_init(&bs, buf, unicodelen * 2); - - /* We assume unicode is in /host/ byte order -- convert to network */ - for (i = 0; i < unicodelen; i++) - aimbs_put16(&bs, unicode[i]); - - if (mpmsg_addsection(sess, mpm, 0x0002, 0x0000, buf, aim_bstream_curpos(&bs)) == -1) { - g_free(buf); - return -1; - } - - return 0; -} - void aim_mpmsg_free(aim_session_t *sess, aim_mpmsg_t *mpm) { aim_mpmsg_section_t *cur; @@ -1729,44 +1181,6 @@ static int incomingim(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, a } /* - * Possible codes: - * AIM_TRANSFER_DENY_NOTSUPPORTED -- "client does not support" - * AIM_TRANSFER_DENY_DECLINE -- "client has declined transfer" - * AIM_TRANSFER_DENY_NOTACCEPTING -- "client is not accepting transfers" - * - */ -int aim_denytransfer(aim_session_t *sess, const char *sender, const guint8 *cookie, guint16 code) -{ - aim_conn_t *conn; - aim_frame_t *fr; - aim_snacid_t snacid; - aim_tlvlist_t *tl = NULL; - - if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004))) - return -EINVAL; - - if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sender)+6))) - return -ENOMEM; - - snacid = aim_cachesnac(sess, 0x0004, 0x000b, 0x0000, NULL, 0); - aim_putsnac(&fr->data, 0x0004, 0x000b, 0x0000, snacid); - - aimbs_putraw(&fr->data, cookie, 8); - - aimbs_put16(&fr->data, 0x0002); /* channel */ - aimbs_put8(&fr->data, strlen(sender)); - aimbs_putraw(&fr->data, (guint8 *)sender, strlen(sender)); - - aim_addtlvtochain16(&tl, 0x0003, code); - aim_writetlvchain(&fr->data, &tl); - aim_freetlvchain(&tl); - - aim_tx_enqueue(sess, fr); - - return 0; -} - -/* * aim_reqicbmparaminfo() * * Request ICBM parameter information. |