| |
1 /* |
| |
2 * Gaim's oscar protocol plugin |
| |
3 * This file is the legal property of its developers. |
| |
4 * Please see the AUTHORS file distributed alongside this file. |
| |
5 * |
| |
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. |
| |
10 * |
| |
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. |
| |
15 * |
| |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| |
19 */ |
| |
20 |
| |
21 /* |
| |
22 * Family 0x0010 - Server stored buddy art |
| |
23 * |
| |
24 * Used for storing and retrieving your cute little buddy icon |
| |
25 * from the AIM servers. |
| |
26 * |
| |
27 */ |
| |
28 |
| |
29 #include "oscar.h" |
| |
30 |
| |
31 /** |
| |
32 * Subtype 0x0002 - Upload your icon. |
| |
33 * |
| |
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. |
| |
38 */ |
| |
39 int |
| |
40 aim_bart_upload(OscarData *od, const guint8 *icon, guint16 iconlen) |
| |
41 { |
| |
42 FlapConnection *conn; |
| |
43 FlapFrame *fr; |
| |
44 aim_snacid_t snacid; |
| |
45 |
| |
46 if (!od || !(conn = flap_connection_findbygroup(od, 0x0010)) || !icon || !iconlen) |
| |
47 return -EINVAL; |
| |
48 |
| |
49 fr = flap_frame_new(od, 0x02, 10 + 2 + 2+iconlen); |
| |
50 snacid = aim_cachesnac(od, 0x0010, 0x0002, 0x0000, NULL, 0); |
| |
51 aim_putsnac(&fr->data, 0x0010, 0x0002, 0x0000, snacid); |
| |
52 |
| |
53 /* The reference number for the icon */ |
| |
54 byte_stream_put16(&fr->data, 1); |
| |
55 |
| |
56 /* The icon */ |
| |
57 byte_stream_put16(&fr->data, iconlen); |
| |
58 byte_stream_putraw(&fr->data, icon, iconlen); |
| |
59 |
| |
60 flap_connection_send(conn, fr); |
| |
61 |
| |
62 return 0; |
| |
63 } |
| |
64 |
| |
65 /** |
| |
66 * Subtype 0x0003 - Acknowledgement for uploading a buddy icon. |
| |
67 * |
| |
68 * You get this honky after you upload a buddy icon. |
| |
69 */ |
| |
70 static int |
| |
71 uploadack(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
| |
72 { |
| |
73 int ret = 0; |
| |
74 aim_rxcallback_t userfunc; |
| |
75 guint16 something, somethingelse; |
| |
76 guint8 onemorething; |
| |
77 |
| |
78 something = byte_stream_get16(bs); |
| |
79 somethingelse = byte_stream_get16(bs); |
| |
80 onemorething = byte_stream_get8(bs); |
| |
81 |
| |
82 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) |
| |
83 ret = userfunc(od, conn, frame); |
| |
84 |
| |
85 return ret; |
| |
86 } |
| |
87 |
| |
88 /** |
| |
89 * Subtype 0x0004 - Request someone's icon. |
| |
90 * |
| |
91 * @param od The oscar session. |
| |
92 * @param sn The screen name of the person who's icon you are requesting. |
| |
93 * @param iconcsum The MD5 checksum of the icon you are requesting. |
| |
94 * @param iconcsumlen Length of the MD5 checksum given above. Should be 10 bytes. |
| |
95 * @return Return 0 if no errors, otherwise return the error number. |
| |
96 */ |
| |
97 int |
| |
98 aim_bart_request(OscarData *od, const char *sn, guint8 iconcsumtype, const guint8 *iconcsum, guint16 iconcsumlen) |
| |
99 { |
| |
100 FlapConnection *conn; |
| |
101 FlapFrame *fr; |
| |
102 aim_snacid_t snacid; |
| |
103 |
| |
104 if (!od || !(conn = flap_connection_findbygroup(od, 0x0010)) || !sn || !strlen(sn) || !iconcsum || !iconcsumlen) |
| |
105 return -EINVAL; |
| |
106 |
| |
107 fr = flap_frame_new(od, 0x02, 10 + 1+strlen(sn) + 4 + 1+iconcsumlen); |
| |
108 snacid = aim_cachesnac(od, 0x0010, 0x0004, 0x0000, NULL, 0); |
| |
109 aim_putsnac(&fr->data, 0x0010, 0x0004, 0x0000, snacid); |
| |
110 |
| |
111 /* Screen name */ |
| |
112 byte_stream_put8(&fr->data, strlen(sn)); |
| |
113 byte_stream_putstr(&fr->data, sn); |
| |
114 |
| |
115 /* Some numbers. You like numbers, right? */ |
| |
116 byte_stream_put8(&fr->data, 0x01); |
| |
117 byte_stream_put16(&fr->data, 0x0001); |
| |
118 byte_stream_put8(&fr->data, iconcsumtype); |
| |
119 |
| |
120 /* Icon string */ |
| |
121 byte_stream_put8(&fr->data, iconcsumlen); |
| |
122 byte_stream_putraw(&fr->data, iconcsum, iconcsumlen); |
| |
123 |
| |
124 flap_connection_send(conn, fr); |
| |
125 |
| |
126 return 0; |
| |
127 } |
| |
128 |
| |
129 /** |
| |
130 * Subtype 0x0005 - Receive a buddy icon. |
| |
131 * |
| |
132 * This is sent in response to a buddy icon request. |
| |
133 */ |
| |
134 static int |
| |
135 parseicon(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
| |
136 { |
| |
137 int ret = 0; |
| |
138 aim_rxcallback_t userfunc; |
| |
139 char *sn; |
| |
140 guint16 flags, iconlen; |
| |
141 guint8 iconcsumtype, iconcsumlen, *iconcsum, *icon; |
| |
142 |
| |
143 sn = byte_stream_getstr(bs, byte_stream_get8(bs)); |
| |
144 flags = byte_stream_get16(bs); |
| |
145 iconcsumtype = byte_stream_get8(bs); |
| |
146 iconcsumlen = byte_stream_get8(bs); |
| |
147 iconcsum = byte_stream_getraw(bs, iconcsumlen); |
| |
148 iconlen = byte_stream_get16(bs); |
| |
149 icon = byte_stream_getraw(bs, iconlen); |
| |
150 |
| |
151 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) |
| |
152 ret = userfunc(od, conn, frame, sn, iconcsumtype, iconcsum, iconcsumlen, icon, iconlen); |
| |
153 |
| |
154 free(sn); |
| |
155 free(iconcsum); |
| |
156 free(icon); |
| |
157 |
| |
158 return ret; |
| |
159 } |
| |
160 |
| |
161 static int |
| |
162 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
| |
163 { |
| |
164 if (snac->subtype == 0x0003) |
| |
165 return uploadack(od, conn, mod, frame, snac, bs); |
| |
166 else if (snac->subtype == 0x0005) |
| |
167 return parseicon(od, conn, mod, frame, snac, bs); |
| |
168 |
| |
169 return 0; |
| |
170 } |
| |
171 |
| |
172 int |
| |
173 bart_modfirst(OscarData *od, aim_module_t *mod) |
| |
174 { |
| |
175 mod->family = 0x0010; |
| |
176 mod->version = 0x0001; |
| |
177 mod->toolid = 0x0010; |
| |
178 mod->toolversion = 0x0629; |
| |
179 mod->flags = 0; |
| |
180 strncpy(mod->name, "bart", sizeof(mod->name)); |
| |
181 mod->snachandler = snachandler; |
| |
182 |
| |
183 return 0; |
| |
184 } |