Wed, 03 Jul 2013 22:18:55 +0530
Renamed PurpleBlistNode to PurpleBListNode
| 13235 | 1 | /* |
| 15884 | 2 | * Purple's oscar protocol plugin |
| 13235 | 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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17280
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 13235 | 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 | * | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
34 | * @param od The oscar session. |
| 13235 | 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 | */ | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
39 | int |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
40 | aim_bart_upload(OscarData *od, const guint8 *icon, guint16 iconlen) |
| 13235 | 41 | { |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
42 | FlapConnection *conn; |
|
22860
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
43 | ByteStream bs; |
| 13235 | 44 | aim_snacid_t snacid; |
| 45 | ||
|
23456
66ab07770438
Replaced family_*'s magic numbers of FLAP families with the constants
Evan Schoenberg <evands@pidgin.im>
parents:
23004
diff
changeset
|
46 | if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_BART)) || !icon || !iconlen) |
| 13235 | 47 | return -EINVAL; |
| 48 | ||
|
22860
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
49 | byte_stream_new(&bs, 2 + 2 + iconlen); |
| 13235 | 50 | |
| 51 | /* The reference number for the icon */ | |
|
22860
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
52 | byte_stream_put16(&bs, 1); |
| 13235 | 53 | |
| 54 | /* The icon */ | |
|
22860
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
55 | byte_stream_put16(&bs, iconlen); |
|
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
56 | byte_stream_putraw(&bs, icon, iconlen); |
| 13235 | 57 | |
|
23456
66ab07770438
Replaced family_*'s magic numbers of FLAP families with the constants
Evan Schoenberg <evands@pidgin.im>
parents:
23004
diff
changeset
|
58 | snacid = aim_cachesnac(od, SNAC_FAMILY_BART, 0x0002, 0x0000, NULL, 0); |
|
30678
78aacd015725
Removed unused "flags" parameter.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
25889
diff
changeset
|
59 | flap_connection_send_snac(od, conn, SNAC_FAMILY_BART, 0x0002, snacid, &bs); |
|
23004
0d9272ff5e50
Minor changes... mostly whitespace related.
Mark Doliner <markdoliner@pidgin.im>
parents:
22860
diff
changeset
|
60 | |
|
22860
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
61 | byte_stream_destroy(&bs); |
|
23004
0d9272ff5e50
Minor changes... mostly whitespace related.
Mark Doliner <markdoliner@pidgin.im>
parents:
22860
diff
changeset
|
62 | |
| 13235 | 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 | */ | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
71 | static int |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
72 | uploadack(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
| 13235 | 73 | { |
| 74 | int ret = 0; | |
| 75 | aim_rxcallback_t userfunc; | |
| 76 | ||
|
33892
ef97228bc5f0
Fix most of warnings for gtk2 and linux
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32978
diff
changeset
|
77 | byte_stream_get16(bs); |
|
ef97228bc5f0
Fix most of warnings for gtk2 and linux
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32978
diff
changeset
|
78 | byte_stream_get16(bs); |
|
ef97228bc5f0
Fix most of warnings for gtk2 and linux
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32978
diff
changeset
|
79 | byte_stream_get8(bs); |
| 13235 | 80 | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
81 | if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
82 | ret = userfunc(od, conn, frame); |
| 13235 | 83 | |
| 84 | return ret; | |
| 85 | } | |
| 86 | ||
| 87 | /** | |
| 88 | * Subtype 0x0004 - Request someone's icon. | |
| 89 | * | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
90 | * @param od The oscar session. |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
23456
diff
changeset
|
91 | * @param bn The name of the buddy whose icon you are requesting. |
| 13235 | 92 | * @param iconcsum The MD5 checksum of the icon you are requesting. |
| 93 | * @param iconcsumlen Length of the MD5 checksum given above. Should be 10 bytes. | |
| 94 | * @return Return 0 if no errors, otherwise return the error number. | |
| 95 | */ | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
96 | int |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
23456
diff
changeset
|
97 | aim_bart_request(OscarData *od, const char *bn, guint8 iconcsumtype, const guint8 *iconcsum, guint16 iconcsumlen) |
| 13235 | 98 | { |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
99 | FlapConnection *conn; |
|
22860
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
100 | ByteStream bs; |
| 13235 | 101 | aim_snacid_t snacid; |
| 102 | ||
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
23456
diff
changeset
|
103 | if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_BART)) || !bn || !strlen(bn) || !iconcsum || !iconcsumlen) |
| 13235 | 104 | return -EINVAL; |
| 105 | ||
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
23456
diff
changeset
|
106 | byte_stream_new(&bs, 1+strlen(bn) + 4 + 1+iconcsumlen); |
| 13235 | 107 | |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
23456
diff
changeset
|
108 | /* Buddy name */ |
|
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
23456
diff
changeset
|
109 | byte_stream_put8(&bs, strlen(bn)); |
|
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
23456
diff
changeset
|
110 | byte_stream_putstr(&bs, bn); |
| 13235 | 111 | |
| 112 | /* Some numbers. You like numbers, right? */ | |
|
22860
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
113 | byte_stream_put8(&bs, 0x01); |
|
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
114 | byte_stream_put16(&bs, 0x0001); |
|
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
115 | byte_stream_put8(&bs, iconcsumtype); |
| 13235 | 116 | |
| 117 | /* Icon string */ | |
|
22860
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
118 | byte_stream_put8(&bs, iconcsumlen); |
|
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
119 | byte_stream_putraw(&bs, iconcsum, iconcsumlen); |
| 13235 | 120 | |
|
23456
66ab07770438
Replaced family_*'s magic numbers of FLAP families with the constants
Evan Schoenberg <evands@pidgin.im>
parents:
23004
diff
changeset
|
121 | snacid = aim_cachesnac(od, SNAC_FAMILY_BART, 0x0004, 0x0000, NULL, 0); |
|
30678
78aacd015725
Removed unused "flags" parameter.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
25889
diff
changeset
|
122 | flap_connection_send_snac(od, conn, SNAC_FAMILY_BART, 0x0004, snacid, &bs); |
|
22860
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
123 | |
|
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
124 | byte_stream_destroy(&bs); |
| 13235 | 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 | */ | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
134 | static int |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
135 | parseicon(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
| 13235 | 136 | { |
| 137 | int ret = 0; | |
| 138 | aim_rxcallback_t userfunc; | |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
23456
diff
changeset
|
139 | char *bn; |
|
33892
ef97228bc5f0
Fix most of warnings for gtk2 and linux
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32978
diff
changeset
|
140 | guint16 iconlen; |
| 13235 | 141 | guint8 iconcsumtype, iconcsumlen, *iconcsum, *icon; |
| 142 | ||
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
23456
diff
changeset
|
143 | bn = byte_stream_getstr(bs, byte_stream_get8(bs)); |
|
32978
15ee0ec69dfa
Validate utf8 for a few random strings that we read, in case AOL or ICQ
Mark Doliner <markdoliner@pidgin.im>
parents:
30678
diff
changeset
|
144 | if (!g_utf8_validate(bn, -1, NULL)) { |
|
15ee0ec69dfa
Validate utf8 for a few random strings that we read, in case AOL or ICQ
Mark Doliner <markdoliner@pidgin.im>
parents:
30678
diff
changeset
|
145 | purple_debug_warning("oscar", "Received SNAC %04hx/%04hx with " |
|
15ee0ec69dfa
Validate utf8 for a few random strings that we read, in case AOL or ICQ
Mark Doliner <markdoliner@pidgin.im>
parents:
30678
diff
changeset
|
146 | "invalid UTF-8 buddy name.\n", snac->family, snac->subtype); |
|
15ee0ec69dfa
Validate utf8 for a few random strings that we read, in case AOL or ICQ
Mark Doliner <markdoliner@pidgin.im>
parents:
30678
diff
changeset
|
147 | g_free(bn); |
|
15ee0ec69dfa
Validate utf8 for a few random strings that we read, in case AOL or ICQ
Mark Doliner <markdoliner@pidgin.im>
parents:
30678
diff
changeset
|
148 | return 1; |
|
15ee0ec69dfa
Validate utf8 for a few random strings that we read, in case AOL or ICQ
Mark Doliner <markdoliner@pidgin.im>
parents:
30678
diff
changeset
|
149 | } |
|
33892
ef97228bc5f0
Fix most of warnings for gtk2 and linux
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32978
diff
changeset
|
150 | byte_stream_get16(bs); /* flags */ |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
151 | iconcsumtype = byte_stream_get8(bs); |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
152 | iconcsumlen = byte_stream_get8(bs); |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
153 | iconcsum = byte_stream_getraw(bs, iconcsumlen); |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
154 | iconlen = byte_stream_get16(bs); |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
155 | icon = byte_stream_getraw(bs, iconlen); |
| 13235 | 156 | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
157 | if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
23456
diff
changeset
|
158 | ret = userfunc(od, conn, frame, bn, iconcsumtype, iconcsum, iconcsumlen, icon, iconlen); |
| 13235 | 159 | |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
23456
diff
changeset
|
160 | g_free(bn); |
|
17280
7c0472208173
Make all the oscar memory allocations and frees use the glib functions to avoid problems when mixing C runtimes.
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
161 | g_free(iconcsum); |
|
7c0472208173
Make all the oscar memory allocations and frees use the glib functions to avoid problems when mixing C runtimes.
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
162 | g_free(icon); |
| 13235 | 163 | |
| 164 | return ret; | |
| 165 | } | |
| 166 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
167 | static int |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
168 | snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
| 13235 | 169 | { |
| 170 | if (snac->subtype == 0x0003) | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
171 | return uploadack(od, conn, mod, frame, snac, bs); |
| 13235 | 172 | else if (snac->subtype == 0x0005) |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
173 | return parseicon(od, conn, mod, frame, snac, bs); |
| 13235 | 174 | |
| 175 | return 0; | |
| 176 | } | |
| 177 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
178 | int |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
179 | bart_modfirst(OscarData *od, aim_module_t *mod) |
| 13235 | 180 | { |
|
23456
66ab07770438
Replaced family_*'s magic numbers of FLAP families with the constants
Evan Schoenberg <evands@pidgin.im>
parents:
23004
diff
changeset
|
181 | mod->family = SNAC_FAMILY_BART; |
| 13235 | 182 | mod->version = 0x0001; |
| 183 | mod->toolid = 0x0010; | |
| 184 | mod->toolversion = 0x0629; | |
| 185 | mod->flags = 0; | |
| 186 | strncpy(mod->name, "bart", sizeof(mod->name)); | |
| 187 | mod->snachandler = snachandler; | |
| 188 | ||
| 189 | return 0; | |
| 190 | } |