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