4805
|
1 /*
|
|
2 * Family 0x0010 - Server stored buddy icons
|
|
3 *
|
|
4 * Used for storing and retrieving your cute little buddy icon
|
|
5 * from the AIM servers.
|
|
6 *
|
|
7 */
|
|
8
|
|
9 #define FAIM_INTERNAL
|
|
10 #include <aim.h>
|
|
11
|
|
12 /**
|
4889
|
13 * Subtype 0x0002 - Upload your icon.
|
|
14 *
|
|
15 * @param sess The oscar session.
|
|
16 * @param conn The icon connection for this session.
|
|
17 * @param num The reference number of the icon you are uploading.
|
|
18 * @param icon The raw data of the icon image file.
|
|
19 * @param iconlen Length of the raw data of the icon image file.
|
|
20 * @return Return 0 if no errors, otherwise return the error number.
|
|
21 */
|
|
22 faim_export int aim_icon_upload(aim_session_t *sess, int num, const fu8_t *icon, fu16_t iconlen)
|
|
23 {
|
|
24 aim_conn_t *conn;
|
|
25 aim_frame_t *fr;
|
|
26 aim_snacid_t snacid;
|
|
27
|
|
28 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0010)) || !num || !icon || !iconlen)
|
|
29 return -EINVAL;
|
|
30
|
|
31 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 2 + 2+iconlen)))
|
|
32 return -ENOMEM;
|
|
33 snacid = aim_cachesnac(sess, 0x0010, 0x0002, 0x0000, NULL, 0);
|
|
34 aim_putsnac(&fr->data, 0x0010, 0x0002, 0x0000, snacid);
|
|
35
|
|
36 /* The reference number for the icon */
|
|
37 aimbs_put16(&fr->data, num);
|
|
38
|
|
39 /* The icon */
|
|
40 aimbs_put16(&fr->data, iconlen);
|
|
41 aimbs_putraw(&fr->data, icon, iconlen);
|
|
42
|
|
43 aim_tx_enqueue(sess, fr);
|
|
44
|
|
45 return 0;
|
|
46 }
|
|
47
|
|
48 /**
|
|
49 * Subtype 0x0003 - Acknowledgement for uploading a buddy icon.
|
|
50 *
|
|
51 * You get this honky after you upload a buddy icon.
|
|
52 */
|
|
53 static int uploadack(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
54 {
|
|
55 int ret = 0;
|
|
56 aim_rxcallback_t userfunc;
|
|
57 fu16_t something, somethingelse;
|
|
58 fu8_t onemorething;
|
|
59
|
|
60 something = aimbs_get16(bs);
|
|
61 somethingelse = aimbs_get16(bs);
|
|
62 onemorething = aimbs_get8(bs);
|
|
63
|
|
64 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
65 ret = userfunc(sess, rx);
|
|
66
|
|
67 return ret;
|
|
68 }
|
|
69
|
|
70 /**
|
4805
|
71 * Subtype 0x0004 - Request someone's icon.
|
|
72 *
|
|
73 * @param sess The oscar session.
|
|
74 * @param conn The icon connection for this session.
|
4889
|
75 * @param sn The screen name of the person who's icon you are requesting.
|
|
76 * @param iconcsum The MD5 checksum of the icon you are requesting.
|
|
77 * @param iconcsumlen Length of the MD5 checksum given above. Should be 10 bytes.
|
4805
|
78 * @return Return 0 if no errors, otherwise return the error number.
|
|
79 */
|
4889
|
80 faim_export int aim_icon_request(aim_session_t *sess, const char *sn, const fu8_t *iconcsum, fu16_t iconcsumlen)
|
4805
|
81 {
|
|
82 aim_conn_t *conn;
|
|
83 aim_frame_t *fr;
|
|
84 aim_snacid_t snacid;
|
|
85
|
4853
|
86 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0010)) || !sn || !strlen(sn) || !iconcsum || !iconcsumlen)
|
4805
|
87 return -EINVAL;
|
|
88
|
4853
|
89 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 1+strlen(sn) + 4 + 1+iconcsumlen)))
|
4805
|
90 return -ENOMEM;
|
|
91 snacid = aim_cachesnac(sess, 0x0010, 0x0004, 0x0000, NULL, 0);
|
|
92 aim_putsnac(&fr->data, 0x0010, 0x0004, 0x0000, snacid);
|
|
93
|
|
94 /* Screen name */
|
|
95 aimbs_put8(&fr->data, strlen(sn));
|
|
96 aimbs_putraw(&fr->data, sn, strlen(sn));
|
|
97
|
4826
|
98 /* Some numbers. You like numbers, right? */
|
|
99 aimbs_put8(&fr->data, 0x01);
|
|
100 aimbs_put16(&fr->data, 0x0001);
|
4805
|
101 aimbs_put8(&fr->data, 0x01);
|
|
102
|
|
103 /* Icon string */
|
4853
|
104 aimbs_put8(&fr->data, iconcsumlen);
|
|
105 aimbs_putraw(&fr->data, iconcsum, iconcsumlen);
|
4805
|
106
|
|
107 aim_tx_enqueue(sess, fr);
|
|
108
|
|
109 return 0;
|
|
110 }
|
|
111
|
|
112 /**
|
|
113 * Subtype 0x0005 - Receive a buddy icon.
|
|
114 *
|
|
115 * This is sent in response to a buddy icon request.
|
|
116 */
|
|
117 static int parseicon(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
118 {
|
4889
|
119 int ret = 0;
|
4805
|
120 aim_rxcallback_t userfunc;
|
|
121 char *sn;
|
4853
|
122 fu16_t flags, iconlen;
|
|
123 fu8_t number, iconcsumlen, *iconcsum, *icon;
|
4805
|
124
|
|
125 sn = aimbs_getstr(bs, aimbs_get8(bs));
|
4853
|
126 flags = aimbs_get16(bs);
|
|
127 number = aimbs_get8(bs);
|
|
128 iconcsumlen = aimbs_get8(bs);
|
|
129 iconcsum = aimbs_getraw(bs, iconcsumlen);
|
4805
|
130 iconlen = aimbs_get16(bs);
|
|
131 icon = aimbs_getraw(bs, iconlen);
|
|
132
|
|
133 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
4872
|
134 ret = userfunc(sess, rx, sn, iconcsum, iconcsumlen, icon, iconlen);
|
4805
|
135
|
4870
|
136 free(sn);
|
4853
|
137 free(iconcsum);
|
4805
|
138 free(icon);
|
|
139
|
4872
|
140 return ret;
|
4805
|
141 }
|
|
142
|
|
143 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
144 {
|
|
145
|
4889
|
146 if (snac->subtype == 0x0003)
|
|
147 return uploadack(sess, mod, rx, snac, bs);
|
|
148 else if (snac->subtype == 0x0005)
|
4805
|
149 return parseicon(sess, mod, rx, snac, bs);
|
|
150
|
|
151 return 0;
|
|
152 }
|
|
153
|
|
154 faim_internal int icon_modfirst(aim_session_t *sess, aim_module_t *mod)
|
|
155 {
|
|
156
|
|
157 mod->family = 0x0010;
|
|
158 mod->version = 0x0001;
|
|
159 mod->toolid = 0x0010;
|
|
160 mod->toolversion = 0x0629;
|
|
161 mod->flags = 0;
|
|
162 strncpy(mod->name, "icon", sizeof(mod->name));
|
|
163 mod->snachandler = snachandler;
|
|
164
|
|
165 return 0;
|
|
166 }
|