2 * Purple's oscar protocol plugin
3 * This file is the legal property of its developers.
4 * Please see the AUTHORS file distributed alongside this file.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 * Family 0x0010 - Server stored buddy art
24 * Used for storing and retrieving your cute little buddy icon
25 * from the AIM servers.
32 * Subtype 0x0002 - Upload your icon.
34 * @param od The oscar session.
35 * @param icon The raw data of the icon image file.
36 * @param iconlen Length of the raw data of the icon image file.
37 * @return Return 0 if no errors, otherwise return the error number.
40 aim_bart_upload(OscarData
*od
, const guint8
*icon
, guint16 iconlen
)
46 if (!od
|| !(conn
= flap_connection_findbygroup(od
, SNAC_FAMILY_BART
)) || !icon
|| !iconlen
)
49 byte_stream_new(&bs
, 2 + 2 + iconlen
);
51 /* The reference number for the icon */
52 byte_stream_put16(&bs
, 1);
55 byte_stream_put16(&bs
, iconlen
);
56 byte_stream_putraw(&bs
, icon
, iconlen
);
58 snacid
= aim_cachesnac(od
, SNAC_FAMILY_BART
, 0x0002, 0x0000, NULL
, 0);
59 flap_connection_send_snac(od
, conn
, SNAC_FAMILY_BART
, 0x0002, snacid
, &bs
);
61 byte_stream_destroy(&bs
);
67 * Subtype 0x0003 - Acknowledgement for uploading a buddy icon.
69 * You get this honky after you upload a buddy icon.
72 uploadack(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
75 aim_rxcallback_t userfunc
;
77 byte_stream_get16(bs
);
78 byte_stream_get16(bs
);
81 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
82 ret
= userfunc(od
, conn
, frame
);
88 * Subtype 0x0004 - Request someone's icon.
90 * @param od The oscar session.
91 * @param bn The name of the buddy whose icon you are requesting.
92 * @param iconcsum The MD5 checksum of the icon you are requesting.
93 * @param iconcsumlen Length of the MD5 checksum given above. Should be 10 bytes.
94 * @return Return 0 if no errors, otherwise return the error number.
97 aim_bart_request(OscarData
*od
, const char *bn
, guint8 iconcsumtype
, const guint8
*iconcsum
, guint16 iconcsumlen
)
103 if (!od
|| !(conn
= flap_connection_findbygroup(od
, SNAC_FAMILY_BART
)) || !bn
|| *bn
== '\0' || !iconcsum
|| !iconcsumlen
)
106 byte_stream_new(&bs
, 1+strlen(bn
) + 4 + 1+iconcsumlen
);
109 byte_stream_put8(&bs
, strlen(bn
));
110 byte_stream_putstr(&bs
, bn
);
112 /* Some numbers. You like numbers, right? */
113 byte_stream_put8(&bs
, 0x01);
114 byte_stream_put16(&bs
, 0x0001);
115 byte_stream_put8(&bs
, iconcsumtype
);
118 byte_stream_put8(&bs
, iconcsumlen
);
119 byte_stream_putraw(&bs
, iconcsum
, iconcsumlen
);
121 snacid
= aim_cachesnac(od
, SNAC_FAMILY_BART
, 0x0004, 0x0000, NULL
, 0);
122 flap_connection_send_snac(od
, conn
, SNAC_FAMILY_BART
, 0x0004, snacid
, &bs
);
124 byte_stream_destroy(&bs
);
130 * Subtype 0x0005 - Receive a buddy icon.
132 * This is sent in response to a buddy icon request.
135 parseicon(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
138 aim_rxcallback_t userfunc
;
141 guint8 iconcsumtype
, iconcsumlen
, *iconcsum
, *icon
;
143 bn
= byte_stream_getstr(bs
, byte_stream_get8(bs
));
144 if (!g_utf8_validate(bn
, -1, NULL
)) {
145 purple_debug_warning("oscar", "Received SNAC %04hx/%04hx with "
146 "invalid UTF-8 buddy name.\n", snac
->family
, snac
->subtype
);
150 byte_stream_get16(bs
); /* flags */
151 iconcsumtype
= byte_stream_get8(bs
);
152 iconcsumlen
= byte_stream_get8(bs
);
153 iconcsum
= byte_stream_getraw(bs
, iconcsumlen
);
154 iconlen
= byte_stream_get16(bs
);
155 icon
= byte_stream_getraw(bs
, iconlen
);
157 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
158 ret
= userfunc(od
, conn
, frame
, bn
, iconcsumtype
, iconcsum
, iconcsumlen
, icon
, iconlen
);
168 snachandler(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
170 if (snac
->subtype
== 0x0003)
171 return uploadack(od
, conn
, mod
, frame
, snac
, bs
);
172 else if (snac
->subtype
== 0x0005)
173 return parseicon(od
, conn
, mod
, frame
, snac
, bs
);
179 bart_modfirst(OscarData
*od
, aim_module_t
*mod
)
181 mod
->family
= SNAC_FAMILY_BART
;
182 mod
->version
= 0x0001;
183 mod
->toolid
= 0x0010;
184 mod
->toolversion
= 0x0629;
186 strncpy(mod
->name
, "bart", sizeof(mod
->name
));
187 mod
->snachandler
= snachandler
;