Mercurial > pidgin
changeset 25975:3f3d21ae1825
Create two helper functions for setting the available message and iTunes
Music Store url. I guess this might be slightly more ineffecient, but
this code is only called when your status changes, and it's much cleaner
this way.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 05 Mar 2009 23:17:01 +0000 |
parents | cf75f0ca4b86 |
children | cef8479194c0 |
files | libpurple/protocols/oscar/bstream.c libpurple/protocols/oscar/family_oservice.c libpurple/protocols/oscar/oscar.h |
diffstat | 3 files changed, 49 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/oscar/bstream.c Thu Mar 05 21:39:09 2009 +0000 +++ b/libpurple/protocols/oscar/bstream.c Thu Mar 05 23:17:01 2009 +0000 @@ -311,3 +311,37 @@ return byte_stream_putle32(bs, atoi(purple_account_get_username(account))); } + +void byte_stream_put_bart_asset(ByteStream *bs, guint16 type, ByteStream *data) +{ + byte_stream_put16(bs, type); + + if (data != NULL && data->len > 0) { + /* Flags. 0x04 means "this asset has data attached to it" */ + byte_stream_put8(bs, 0x04); /* Flags */ + byte_stream_put8(bs, data->len); /* Length */ + byte_stream_rewind(data); + byte_stream_putbs(bs, data, data->len); /* Data */ + } else { + byte_stream_put8(bs, 0x00); /* No flags */ + byte_stream_put8(bs, 0x00); /* Length */ + /* No data */ + } +} + +void byte_stream_put_bart_asset_str(ByteStream *bs, guint16 type, const char *datastr) +{ + ByteStream data; + size_t len = datastr != NULL ? strlen(datastr) : 0; + + if (len > 0) { + byte_stream_new(&data, 2 + len + 2); + byte_stream_put16(&data, len); /* Length */ + byte_stream_putstr(&data, datastr); /* String */ + byte_stream_put16(&data, 0x0000); /* Unknown */ + byte_stream_put_bart_asset(bs, type, &data); + byte_stream_destroy(&data); + } else { + byte_stream_put_bart_asset(bs, type, NULL); + } +}
--- a/libpurple/protocols/oscar/family_oservice.c Thu Mar 05 21:39:09 2009 +0000 +++ b/libpurple/protocols/oscar/family_oservice.c Thu Mar 05 23:17:01 2009 +0000 @@ -853,28 +853,15 @@ if (setavailmsg) { - int availmsglen, itmsurllen; + size_t availmsglen, itmsurllen; ByteStream tmpbs; availmsglen = (availmsg != NULL) ? strlen(availmsg) : 0; itmsurllen = (itmsurl != NULL) ? strlen(itmsurl) : 0; byte_stream_new(&tmpbs, availmsglen + 8 + itmsurllen + 8); - byte_stream_put16(&tmpbs, 0x0002); - byte_stream_put8(&tmpbs, 0x04); /* Flags */ - byte_stream_put8(&tmpbs, availmsglen + 4); - byte_stream_put16(&tmpbs, availmsglen); - if (availmsglen > 0) - byte_stream_putstr(&tmpbs, availmsg); - byte_stream_put16(&tmpbs, 0x0000); - - byte_stream_put16(&tmpbs, 0x0009); - byte_stream_put8(&tmpbs, 0x04); /* Flags */ - byte_stream_put8(&tmpbs, itmsurllen + 4); - byte_stream_put16(&tmpbs, itmsurllen); - if (itmsurllen > 0) - byte_stream_putstr(&tmpbs, itmsurl); - byte_stream_put16(&tmpbs, 0x0000); + byte_stream_put_bart_asset_str(&tmpbs, 0x0002, availmsg); + byte_stream_put_bart_asset_str(&tmpbs, 0x0009, itmsurl); aim_tlvlist_add_raw(&tlvlist, 0x001d, byte_stream_curpos(&tmpbs), tmpbs.data);
--- a/libpurple/protocols/oscar/oscar.h Thu Mar 05 21:39:09 2009 +0000 +++ b/libpurple/protocols/oscar/oscar.h Thu Mar 05 23:17:01 2009 +0000 @@ -1594,6 +1594,18 @@ int byte_stream_putuid(ByteStream *bs, OscarData *od); int byte_stream_putcaps(ByteStream *bs, guint32 caps); +/** + * Inserts a BART asset block into the given byte stream. The flags + * and length are set appropriately based on the value of data. + */ +void byte_stream_put_bart_asset(ByteStream *bs, guint16 type, ByteStream *data); + +/** + * A helper function that calls byte_stream_put_bart_asset with the + * appropriate data ByteStream given the datastr. + */ +void byte_stream_put_bart_asset_str(ByteStream *bs, guint16 type, const char *datastr); + /* * Generic SNAC structure. Rarely if ever used. */