Beispiel #1
0
/* XXX pass these in better */
int aim_setuserinterests(aim_session_t *sess, aim_conn_t *conn, const char *interest1, const char *interest2, const char *interest3, const char *interest4, const char *interest5, guint16 privacy)
{
    aim_frame_t *fr;
    aim_tlvlist_t *tl = NULL;

    /* ?? privacy ?? */
    aim_addtlvtochain16(&tl, 0x000a, privacy);

    if (interest1)
        aim_addtlvtochain_raw(&tl, 0x0000b, strlen(interest1), (guint8 *)interest1);
    if (interest2)
        aim_addtlvtochain_raw(&tl, 0x0000b, strlen(interest2), (guint8 *)interest2);
    if (interest3)
        aim_addtlvtochain_raw(&tl, 0x0000b, strlen(interest3), (guint8 *)interest3);
    if (interest4)
        aim_addtlvtochain_raw(&tl, 0x0000b, strlen(interest4), (guint8 *)interest4);
    if (interest5)
        aim_addtlvtochain_raw(&tl, 0x0000b, strlen(interest5), (guint8 *)interest5);

    if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_sizetlvchain(&tl))))
        return -ENOMEM;

    aim_cachesnac(sess, 0x0002, 0x000f, 0x0000, NULL, 0);

    aim_putsnac(&fr->data, 0x0002, 0x000f, 0x0000, 0);
    aim_writetlvchain(&fr->data, &tl);
    aim_freetlvchain(&tl);

    aim_tx_enqueue(sess, fr);

    return 0;
}
Beispiel #2
0
/**
 * aim_readtlvchain_len - Read a TLV chain from a buffer.
 * @param bs Input bstream
 * @param len The max length in bytes that will be read.
 *        There are a number of places where you want to read in a tlvchain, 
 *        but the chain is not at the end of the SNAC, and the chain is 
 *        preceeded by the length of the TLVs.  So you can limit that with this.
 *
 * Reads and parses a series of TLV patterns from a data buffer; the
 * returned structure is manipulatable with the rest of the TLV
 * routines.  When done with a TLV chain, aim_freetlvchain() should
 * be called to free the dynamic substructures.
 *
 * XXX There should be a flag setable here to have the tlvlist contain
 * bstream references, so that at least the ->value portion of each 
 * element doesn't need to be malloc/memcpy'd.  This could prove to be
 * just as effecient as the in-place TLV parsing used in a couple places
 * in libfaim.
 *
 */
faim_internal aim_tlvlist_t *aim_readtlvchain_len(aim_bstream_t *bs, fu16_t len)
{
	aim_tlvlist_t *list = NULL, *cur;

	while ((aim_bstream_empty(bs) > 0) && (len > 0)) {
		fu16_t type, length;

		type = aimbs_get16(bs);
		length = aimbs_get16(bs);

		if (length > aim_bstream_empty(bs)) {
			aim_freetlvchain(&list);
			return NULL;
		}

		cur = (aim_tlvlist_t *)malloc(sizeof(aim_tlvlist_t));
		if (!cur) {
			aim_freetlvchain(&list);
			return NULL;
		}

		memset(cur, 0, sizeof(aim_tlvlist_t));

		cur->tlv = createtlv();
		if (!cur->tlv) {
			free(cur);
			aim_freetlvchain(&list);
			return NULL;
		}
		cur->tlv->type = type;
		if ((cur->tlv->length = length)) {
		       cur->tlv->value = aimbs_getraw(bs, length);
		       if (!cur->tlv->value) {
			       freetlv(&cur->tlv);
			       free(cur);
			       aim_freetlvchain(&list);
			       return NULL;
		       }
		}

		len -= aim_sizetlvchain(&cur);
		cur->next = list;
		list = cur;
	}

	return list;
}
Beispiel #3
0
/*
 * aim_bos_setprofile(profile)
 *
 * Gives BOS your profile.
 *
 */
int aim_bos_setprofile(aim_session_t *sess, aim_conn_t *conn, const char *profile, const char *awaymsg, guint32 caps)
{
    static const char defencoding[] = {"text/aolrtf; charset=\"utf-8\""};
    aim_frame_t *fr;
    aim_tlvlist_t *tl = NULL;
    aim_snacid_t snacid;

    /* Build to packet first to get real length */
    if (profile) {
        aim_addtlvtochain_raw(&tl, 0x0001, strlen(defencoding), (guint8 *)defencoding);
        aim_addtlvtochain_raw(&tl, 0x0002, strlen(profile), (guint8 *)profile);
    }

    /*
     * So here's how this works:
     *   - You are away when you have a non-zero-length type 4 TLV stored.
     *   - You become unaway when you clear the TLV with a zero-length
     *       type 4 TLV.
     *   - If you do not send the type 4 TLV, your status does not change
     *       (that is, if you were away, you'll remain away).
     */
    if (awaymsg) {
        if (strlen(awaymsg)) {
            aim_addtlvtochain_raw(&tl, 0x0003, strlen(defencoding), (guint8 *)defencoding);
            aim_addtlvtochain_raw(&tl, 0x0004, strlen(awaymsg), (guint8 *)awaymsg);
        } else
            aim_addtlvtochain_noval(&tl, 0x0004);
    }

    aim_addtlvtochain_caps(&tl, 0x0005, caps);

    if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + aim_sizetlvchain(&tl))))
        return -ENOMEM;

    snacid = aim_cachesnac(sess, 0x0002, 0x0004, 0x0000, NULL, 0);

    aim_putsnac(&fr->data, 0x0002, 0x004, 0x0000, snacid);
    aim_writetlvchain(&fr->data, &tl);
    aim_freetlvchain(&tl);

    aim_tx_enqueue(sess, fr);

    return 0;
}
Beispiel #4
0
/*
 * Set directory profile data (not the same as aim_bos_setprofile!)
 *
 * privacy: 1 to allow searching, 0 to disallow.
 */
int aim_setdirectoryinfo(aim_session_t *sess, aim_conn_t *conn, const char *first, const char *middle, const char *last, const char *maiden, const char *nickname, const char *street, const char *city, const char *state, const char *zip, int country, guint16 privacy)
{
    aim_frame_t *fr;
    aim_snacid_t snacid;
    aim_tlvlist_t *tl = NULL;


    aim_addtlvtochain16(&tl, 0x000a, privacy);

    if (first)
        aim_addtlvtochain_raw(&tl, 0x0001, strlen(first), (guint8 *)first);
    if (last)
        aim_addtlvtochain_raw(&tl, 0x0002, strlen(last), (guint8 *)last);
    if (middle)
        aim_addtlvtochain_raw(&tl, 0x0003, strlen(middle), (guint8 *)middle);
    if (maiden)
        aim_addtlvtochain_raw(&tl, 0x0004, strlen(maiden), (guint8 *)maiden);

    if (state)
        aim_addtlvtochain_raw(&tl, 0x0007, strlen(state), (guint8 *)state);
    if (city)
        aim_addtlvtochain_raw(&tl, 0x0008, strlen(city), (guint8 *)city);

    if (nickname)
        aim_addtlvtochain_raw(&tl, 0x000c, strlen(nickname), (guint8 *)nickname);
    if (zip)
        aim_addtlvtochain_raw(&tl, 0x000d, strlen(zip), (guint8 *)zip);

    if (street)
        aim_addtlvtochain_raw(&tl, 0x0021, strlen(street), (guint8 *)street);

    if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_sizetlvchain(&tl))))
        return -ENOMEM;

    snacid = aim_cachesnac(sess, 0x0002, 0x0009, 0x0000, NULL, 0);

    aim_putsnac(&fr->data, 0x0002, 0x0009, 0x0000, snacid);
    aim_writetlvchain(&fr->data, &tl);
    aim_freetlvchain(&tl);

    aim_tx_enqueue(sess, fr);

    return 0;
}
Beispiel #5
0
/*
 * Note that the inner TLV chain will not be modifiable as a tlvchain once
 * it is written using this.  Or rather, it can be, but updates won't be
 * made to this.
 *
 * XXX should probably support sublists for real.
 * 
 * This is so neat.
 *
 */
faim_internal int aim_addtlvtochain_frozentlvlist(aim_tlvlist_t **list, fu16_t type, aim_tlvlist_t **tl)
{
	fu8_t *buf;
	int buflen;
	aim_bstream_t bs;

	buflen = aim_sizetlvchain(tl);

	if (buflen <= 0)
		return 0;

	if (!(buf = malloc(buflen)))
		return 0;

	aim_bstream_init(&bs, buf, buflen);

	aim_writetlvchain(&bs, tl);

	aim_addtlvtochain_raw(list, type, aim_bstream_curpos(&bs), buf);

	free(buf);

	return buflen;
}