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 *
|
|
34 * @param sess The oscar session.
|
|
35 * @param conn The icon connection for this session.
|
|
36 * @param icon The raw data of the icon image file.
|
|
37 * @param iconlen Length of the raw data of the icon image file.
|
|
38 * @return Return 0 if no errors, otherwise return the error number.
|
|
39 */
|
13239
|
40 faim_export int aim_bart_upload(OscarSession *sess, const guint8 *icon, guint16 iconlen)
|
13234
|
41 {
|
13239
|
42 OscarConnection *conn;
|
|
43 FlapFrame *fr;
|
13234
|
44 aim_snacid_t snacid;
|
|
45
|
|
46 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0010)) || !icon || !iconlen)
|
|
47 return -EINVAL;
|
|
48
|
|
49 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 2 + 2+iconlen)))
|
|
50 return -ENOMEM;
|
|
51 snacid = aim_cachesnac(sess, 0x0010, 0x0002, 0x0000, NULL, 0);
|
|
52 aim_putsnac(&fr->data, 0x0010, 0x0002, 0x0000, snacid);
|
|
53
|
|
54 /* The reference number for the icon */
|
|
55 aimbs_put16(&fr->data, 1);
|
|
56
|
|
57 /* The icon */
|
|
58 aimbs_put16(&fr->data, iconlen);
|
|
59 aimbs_putraw(&fr->data, icon, iconlen);
|
|
60
|
|
61 aim_tx_enqueue(sess, fr);
|
|
62
|
|
63 return 0;
|
|
64 }
|
|
65
|
|
66 /**
|
|
67 * Subtype 0x0003 - Acknowledgement for uploading a buddy icon.
|
|
68 *
|
|
69 * You get this honky after you upload a buddy icon.
|
|
70 */
|
13239
|
71 static int uploadack(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, 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
|
|
78 something = aimbs_get16(bs);
|
|
79 somethingelse = aimbs_get16(bs);
|
|
80 onemorething = aimbs_get8(bs);
|
|
81
|
|
82 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
83 ret = userfunc(sess, rx);
|
|
84
|
|
85 return ret;
|
|
86 }
|
|
87
|
|
88 /**
|
|
89 * Subtype 0x0004 - Request someone's icon.
|
|
90 *
|
|
91 * @param sess The oscar session.
|
|
92 * @param conn The icon connection for this session.
|
|
93 * @param sn The screen name of the person who's icon you are requesting.
|
|
94 * @param iconcsum The MD5 checksum of the icon you are requesting.
|
|
95 * @param iconcsumlen Length of the MD5 checksum given above. Should be 10 bytes.
|
|
96 * @return Return 0 if no errors, otherwise return the error number.
|
|
97 */
|
13239
|
98 faim_export int aim_bart_request(OscarSession *sess, const char *sn, guint8 iconcsumtype, const guint8 *iconcsum, guint16 iconcsumlen)
|
13234
|
99 {
|
13239
|
100 OscarConnection *conn;
|
|
101 FlapFrame *fr;
|
13234
|
102 aim_snacid_t snacid;
|
|
103
|
|
104 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0010)) || !sn || !strlen(sn) || !iconcsum || !iconcsumlen)
|
|
105 return -EINVAL;
|
|
106
|
|
107 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 1+strlen(sn) + 4 + 1+iconcsumlen)))
|
|
108 return -ENOMEM;
|
|
109 snacid = aim_cachesnac(sess, 0x0010, 0x0004, 0x0000, NULL, 0);
|
|
110 aim_putsnac(&fr->data, 0x0010, 0x0004, 0x0000, snacid);
|
|
111
|
|
112 /* Screen name */
|
|
113 aimbs_put8(&fr->data, strlen(sn));
|
|
114 aimbs_putstr(&fr->data, sn);
|
|
115
|
|
116 /* Some numbers. You like numbers, right? */
|
|
117 aimbs_put8(&fr->data, 0x01);
|
|
118 aimbs_put16(&fr->data, 0x0001);
|
|
119 aimbs_put8(&fr->data, iconcsumtype);
|
|
120
|
|
121 /* Icon string */
|
|
122 aimbs_put8(&fr->data, iconcsumlen);
|
|
123 aimbs_putraw(&fr->data, iconcsum, iconcsumlen);
|
|
124
|
|
125 aim_tx_enqueue(sess, fr);
|
|
126
|
|
127 return 0;
|
|
128 }
|
|
129
|
|
130 /**
|
|
131 * Subtype 0x0005 - Receive a buddy icon.
|
|
132 *
|
|
133 * This is sent in response to a buddy icon request.
|
|
134 */
|
13239
|
135 static int parseicon(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, 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
|
|
143 sn = aimbs_getstr(bs, aimbs_get8(bs));
|
|
144 flags = aimbs_get16(bs);
|
|
145 iconcsumtype = aimbs_get8(bs);
|
|
146 iconcsumlen = aimbs_get8(bs);
|
|
147 iconcsum = aimbs_getraw(bs, iconcsumlen);
|
|
148 iconlen = aimbs_get16(bs);
|
|
149 icon = aimbs_getraw(bs, iconlen);
|
|
150
|
|
151 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
152 ret = userfunc(sess, rx, sn, iconcsumtype, iconcsum, iconcsumlen, icon, iconlen);
|
|
153
|
|
154 free(sn);
|
|
155 free(iconcsum);
|
|
156 free(icon);
|
|
157
|
|
158 return ret;
|
|
159 }
|
|
160
|
13239
|
161 static int snachandler(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
162 {
|
|
163
|
|
164 if (snac->subtype == 0x0003)
|
|
165 return uploadack(sess, mod, rx, snac, bs);
|
|
166 else if (snac->subtype == 0x0005)
|
|
167 return parseicon(sess, mod, rx, snac, bs);
|
|
168
|
|
169 return 0;
|
|
170 }
|
|
171
|
13239
|
172 faim_internal int bart_modfirst(OscarSession *sess, aim_module_t *mod)
|
13234
|
173 {
|
|
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 }
|