13234
|
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 *
|
13592
|
34 * @param od The oscar session.
|
13234
|
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 */
|
13592
|
39 int
|
|
40 aim_bart_upload(OscarData *od, const guint8 *icon, guint16 iconlen)
|
13234
|
41 {
|
13592
|
42 FlapConnection *conn;
|
13239
|
43 FlapFrame *fr;
|
13234
|
44 aim_snacid_t snacid;
|
|
45
|
13592
|
46 if (!od || !(conn = flap_connection_findbygroup(od, 0x0010)) || !icon || !iconlen)
|
13234
|
47 return -EINVAL;
|
|
48
|
13592
|
49 fr = flap_frame_new(od, 0x02, 10 + 2 + 2+iconlen);
|
|
50 snacid = aim_cachesnac(od, 0x0010, 0x0002, 0x0000, NULL, 0);
|
13234
|
51 aim_putsnac(&fr->data, 0x0010, 0x0002, 0x0000, snacid);
|
|
52
|
|
53 /* The reference number for the icon */
|
13592
|
54 byte_stream_put16(&fr->data, 1);
|
13234
|
55
|
|
56 /* The icon */
|
13592
|
57 byte_stream_put16(&fr->data, iconlen);
|
|
58 byte_stream_putraw(&fr->data, icon, iconlen);
|
13234
|
59
|
13592
|
60 flap_connection_send(conn, fr);
|
13234
|
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 */
|
13592
|
70 static int
|
|
71 uploadack(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
72 {
|
|
73 int ret = 0;
|
|
74 aim_rxcallback_t userfunc;
|
|
75 guint16 something, somethingelse;
|
|
76 guint8 onemorething;
|
|
77
|
13592
|
78 something = byte_stream_get16(bs);
|
|
79 somethingelse = byte_stream_get16(bs);
|
|
80 onemorething = byte_stream_get8(bs);
|
13234
|
81
|
13592
|
82 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
83 ret = userfunc(od, conn, frame);
|
13234
|
84
|
|
85 return ret;
|
|
86 }
|
|
87
|
|
88 /**
|
|
89 * Subtype 0x0004 - Request someone's icon.
|
|
90 *
|
13592
|
91 * @param od The oscar session.
|
13234
|
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 */
|
13592
|
97 int
|
|
98 aim_bart_request(OscarData *od, const char *sn, guint8 iconcsumtype, const guint8 *iconcsum, guint16 iconcsumlen)
|
13234
|
99 {
|
13592
|
100 FlapConnection *conn;
|
13239
|
101 FlapFrame *fr;
|
13234
|
102 aim_snacid_t snacid;
|
|
103
|
13592
|
104 if (!od || !(conn = flap_connection_findbygroup(od, 0x0010)) || !sn || !strlen(sn) || !iconcsum || !iconcsumlen)
|
13234
|
105 return -EINVAL;
|
|
106
|
13592
|
107 fr = flap_frame_new(od, 0x02, 10 + 1+strlen(sn) + 4 + 1+iconcsumlen);
|
|
108 snacid = aim_cachesnac(od, 0x0010, 0x0004, 0x0000, NULL, 0);
|
13234
|
109 aim_putsnac(&fr->data, 0x0010, 0x0004, 0x0000, snacid);
|
|
110
|
|
111 /* Screen name */
|
13592
|
112 byte_stream_put8(&fr->data, strlen(sn));
|
|
113 byte_stream_putstr(&fr->data, sn);
|
13234
|
114
|
|
115 /* Some numbers. You like numbers, right? */
|
13592
|
116 byte_stream_put8(&fr->data, 0x01);
|
|
117 byte_stream_put16(&fr->data, 0x0001);
|
|
118 byte_stream_put8(&fr->data, iconcsumtype);
|
13234
|
119
|
|
120 /* Icon string */
|
13592
|
121 byte_stream_put8(&fr->data, iconcsumlen);
|
|
122 byte_stream_putraw(&fr->data, iconcsum, iconcsumlen);
|
13234
|
123
|
13592
|
124 flap_connection_send(conn, fr);
|
13234
|
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 */
|
13592
|
134 static int
|
|
135 parseicon(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
136 {
|
|
137 int ret = 0;
|
|
138 aim_rxcallback_t userfunc;
|
|
139 char *sn;
|
|
140 guint16 flags, iconlen;
|
|
141 guint8 iconcsumtype, iconcsumlen, *iconcsum, *icon;
|
|
142
|
13592
|
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);
|
13234
|
150
|
13592
|
151 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
152 ret = userfunc(od, conn, frame, sn, iconcsumtype, iconcsum, iconcsumlen, icon, iconlen);
|
13234
|
153
|
|
154 free(sn);
|
|
155 free(iconcsum);
|
|
156 free(icon);
|
|
157
|
|
158 return ret;
|
|
159 }
|
|
160
|
13592
|
161 static int
|
|
162 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
163 {
|
|
164 if (snac->subtype == 0x0003)
|
13592
|
165 return uploadack(od, conn, mod, frame, snac, bs);
|
13234
|
166 else if (snac->subtype == 0x0005)
|
13592
|
167 return parseicon(od, conn, mod, frame, snac, bs);
|
13234
|
168
|
|
169 return 0;
|
|
170 }
|
|
171
|
13592
|
172 int
|
|
173 bart_modfirst(OscarData *od, aim_module_t *mod)
|
13234
|
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 }
|