Sun, 17 Oct 2010 03:55:04 +0000
Fix for CVE-2010-3711. Properly validate the return value from
purple_base64_decode() (the CVE issue) and purple_base16_decode() (just a bug).
Coincidentally, this should also fix #12614.
committer: John Bailey <rekkanoryo@rekkanoryo.org>
| 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:
17443
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 13235 | 19 | */ |
| 20 | ||
| 21 | /* | |
| 22 | * Family 0x000e - Routines for the Chat service. | |
| 23 | * | |
| 24 | */ | |
| 25 | ||
| 26 | #include "oscar.h" | |
| 27 | ||
| 28 | #include <string.h> | |
| 29 | ||
| 30 | /* Stored in the ->internal of chat connections */ | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
31 | struct chatconnpriv |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
32 | { |
| 13235 | 33 | guint16 exchange; |
| 34 | char *name; | |
| 35 | guint16 instance; | |
| 36 | }; | |
| 37 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
38 | void |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
39 | flap_connection_destroy_chat(OscarData *od, FlapConnection *conn) |
| 13235 | 40 | { |
| 41 | struct chatconnpriv *ccp = (struct chatconnpriv *)conn->internal; | |
| 42 | ||
| 43 | if (ccp) | |
|
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
|
44 | g_free(ccp->name); |
|
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
|
45 | g_free(ccp); |
| 13235 | 46 | |
| 47 | return; | |
| 48 | } | |
| 49 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
50 | int |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
51 | aim_chat_readroominfo(ByteStream *bs, struct aim_chat_roominfo *outinfo) |
| 13235 | 52 | { |
| 53 | if (!bs || !outinfo) | |
| 54 | return 0; | |
| 55 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
56 | outinfo->exchange = byte_stream_get16(bs); |
|
15308
2bfe4510454e
[gaim-migrate @ 18036]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
57 | outinfo->namelen = byte_stream_get8(bs); |
|
15316
014a37d4232f
[gaim-migrate @ 18044]
Mark Doliner <markdoliner@pidgin.im>
parents:
15308
diff
changeset
|
58 | outinfo->name = (char *)byte_stream_getraw(bs, outinfo->namelen); |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
59 | outinfo->instance = byte_stream_get16(bs); |
| 13235 | 60 | |
| 61 | return 0; | |
| 62 | } | |
| 63 | ||
| 64 | /* | |
| 65 | * Subtype 0x0002 - General room information. Lots of stuff. | |
| 66 | * | |
| 67 | * Values I know are in here but I haven't attached | |
| 68 | * them to any of the 'Unknown's: | |
| 69 | * - Language (English) | |
| 70 | * | |
| 71 | */ | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
72 | static int |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
73 | infoupdate(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
| 13235 | 74 | { |
| 75 | aim_rxcallback_t userfunc; | |
| 76 | int ret = 0; | |
| 77 | guint8 detaillevel = 0; | |
| 78 | struct aim_chat_roominfo roominfo; | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
79 | GSList *tlvlist; |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
80 | guint16 maxmsglen, maxvisiblemsglen; |
| 13235 | 81 | |
| 82 | aim_chat_readroominfo(bs, &roominfo); | |
| 83 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
84 | detaillevel = byte_stream_get8(bs); |
| 13235 | 85 | |
| 86 | if (detaillevel != 0x02) { | |
| 15884 | 87 | purple_debug_misc("oscar", "faim: chat_roomupdateinfo: detail level %d not supported\n", detaillevel); |
| 13235 | 88 | return 1; |
| 89 | } | |
| 90 | ||
| 91 | /* | |
| 92 | * Everything else are TLVs. | |
| 93 | */ | |
| 94 | tlvlist = aim_tlvlist_read(bs); | |
| 95 | ||
| 96 | /* | |
| 97 | * Type 0x00d1: Maximum Message Length | |
| 98 | */ | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
99 | maxmsglen = aim_tlv_get16(tlvlist, 0x00d1, 1); |
| 13235 | 100 | |
| 101 | /* | |
| 102 | * Type 0x00da: Maximum visible message length | |
| 103 | */ | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
104 | maxvisiblemsglen = aim_tlv_get16(tlvlist, 0x00da, 1); |
| 13235 | 105 | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
106 | if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) { |
|
30663
8dac59982e22
Turns out that ncc doesn't catch everything, so continue killing things mercilessly.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30662
diff
changeset
|
107 | ret = userfunc(od, conn, frame, maxmsglen, maxvisiblemsglen); |
| 13235 | 108 | } |
| 109 | ||
|
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
|
110 | g_free(roominfo.name); |
| 13235 | 111 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
112 | aim_tlvlist_free(tlvlist); |
| 13235 | 113 | |
| 114 | return ret; | |
| 115 | } | |
| 116 | ||
| 117 | /* Subtypes 0x0003 and 0x0004 */ | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
118 | static int |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
119 | userlistchange(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
| 13235 | 120 | { |
| 121 | aim_userinfo_t *userinfo = NULL; | |
| 122 | aim_rxcallback_t userfunc; | |
| 123 | int curcount = 0, ret = 0; | |
| 124 | ||
| 30668 | 125 | while (byte_stream_bytes_left(bs)) { |
| 13235 | 126 | curcount++; |
|
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
|
127 | userinfo = g_realloc(userinfo, curcount * sizeof(aim_userinfo_t)); |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
128 | aim_info_extract(od, bs, &userinfo[curcount-1]); |
| 13235 | 129 | } |
| 130 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
131 | if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
132 | ret = userfunc(od, conn, frame, curcount, userinfo); |
| 13235 | 133 | |
| 134 | aim_info_free(userinfo); | |
|
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
|
135 | g_free(userinfo); |
| 13235 | 136 | |
| 137 | return ret; | |
| 138 | } | |
| 139 | ||
| 140 | /* | |
| 141 | * Subtype 0x0005 - Send a Chat Message. | |
| 142 | * | |
| 143 | * Possible flags: | |
| 144 | * AIM_CHATFLAGS_NOREFLECT -- Unset the flag that requests messages | |
| 145 | * should be sent to their sender. | |
| 146 | * AIM_CHATFLAGS_AWAY -- Mark the message as an autoresponse | |
| 147 | * (Note that WinAIM does not honor this, | |
| 148 | * and displays the message as normal.) | |
| 149 | * | |
| 150 | * XXX convert this to use tlvchains | |
| 151 | */ | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
152 | int |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
153 | aim_chat_send_im(OscarData *od, FlapConnection *conn, guint16 flags, const gchar *msg, int msglen, const char *encoding, const char *language) |
| 13235 | 154 | { |
| 155 | int i; | |
|
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
|
156 | ByteStream bs; |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
157 | IcbmCookie *cookie; |
| 13235 | 158 | aim_snacid_t snacid; |
| 159 | guint8 ckstr[8]; | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
160 | GSList *tlvlist = NULL, *inner_tlvlist = NULL; |
| 13235 | 161 | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
162 | if (!od || !conn || !msg || (msglen <= 0)) |
| 13235 | 163 | return 0; |
| 164 | ||
|
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
|
165 | byte_stream_new(&bs, 1142); |
| 13235 | 166 | |
|
23456
66ab07770438
Replaced family_*'s magic numbers of FLAP families with the constants
Evan Schoenberg <evands@pidgin.im>
parents:
23004
diff
changeset
|
167 | snacid = aim_cachesnac(od, SNAC_FAMILY_CHAT, 0x0005, 0x0000, NULL, 0); |
| 13235 | 168 | |
| 169 | /* | |
| 170 | * Cookie | |
| 171 | * | |
| 172 | * XXX mkcookie should generate the cookie and cache it in one | |
| 173 | * operation to preserve uniqueness. | |
| 174 | */ | |
| 175 | for (i = 0; i < 8; i++) | |
| 176 | ckstr[i] = (guint8)rand(); | |
| 177 | ||
| 178 | cookie = aim_mkcookie(ckstr, AIM_COOKIETYPE_CHAT, NULL); | |
| 179 | cookie->data = NULL; /* XXX store something useful here */ | |
| 180 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
181 | aim_cachecookie(od, cookie); |
| 13235 | 182 | |
| 183 | /* ICBM Header */ | |
|
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
|
184 | byte_stream_putraw(&bs, ckstr, 8); /* Cookie */ |
|
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
|
185 | byte_stream_put16(&bs, 0x0003); /* Channel */ |
| 13235 | 186 | |
| 187 | /* | |
| 188 | * Type 1: Flag meaning this message is destined to the room. | |
| 189 | */ | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
190 | aim_tlvlist_add_noval(&tlvlist, 0x0001); |
| 13235 | 191 | |
| 192 | /* | |
| 193 | * Type 6: Reflect | |
| 194 | */ | |
| 195 | if (!(flags & AIM_CHATFLAGS_NOREFLECT)) | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
196 | aim_tlvlist_add_noval(&tlvlist, 0x0006); |
| 13235 | 197 | |
| 198 | /* | |
| 199 | * Type 7: Autoresponse | |
| 200 | */ | |
| 201 | if (flags & AIM_CHATFLAGS_AWAY) | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
202 | aim_tlvlist_add_noval(&tlvlist, 0x0007); |
| 13235 | 203 | |
| 204 | /* | |
| 205 | * SubTLV: Type 1: Message | |
| 206 | */ | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
207 | aim_tlvlist_add_raw(&inner_tlvlist, 0x0001, msglen, (guchar *)msg); |
| 13235 | 208 | |
| 209 | /* | |
| 210 | * SubTLV: Type 2: Encoding | |
| 211 | */ | |
| 212 | if (encoding != NULL) | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
213 | aim_tlvlist_add_str(&inner_tlvlist, 0x0002, encoding); |
| 13235 | 214 | |
| 215 | /* | |
| 216 | * SubTLV: Type 3: Language | |
| 217 | */ | |
| 218 | if (language != NULL) | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
219 | aim_tlvlist_add_str(&inner_tlvlist, 0x0003, language); |
| 13235 | 220 | |
| 221 | /* | |
| 222 | * Type 5: Message block. Contains more TLVs. | |
| 223 | * | |
| 224 | * This could include other information... We just | |
| 225 | * put in a message TLV however. | |
| 226 | * | |
| 227 | */ | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
228 | aim_tlvlist_add_frozentlvlist(&tlvlist, 0x0005, &inner_tlvlist); |
| 13235 | 229 | |
|
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
|
230 | aim_tlvlist_write(&bs, &tlvlist); |
| 13235 | 231 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
232 | aim_tlvlist_free(inner_tlvlist); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
233 | aim_tlvlist_free(tlvlist); |
| 13235 | 234 | |
|
30678
78aacd015725
Removed unused "flags" parameter.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
235 | flap_connection_send_snac(od, conn, SNAC_FAMILY_CHAT, 0x0005, snacid, &bs); |
| 13235 | 236 | |
|
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
|
237 | byte_stream_destroy(&bs); |
|
23004
0d9272ff5e50
Minor changes... mostly whitespace related.
Mark Doliner <markdoliner@pidgin.im>
parents:
22860
diff
changeset
|
238 | |
| 13235 | 239 | return 0; |
| 240 | } | |
| 241 | ||
| 242 | /* | |
| 243 | * Subtype 0x0006 | |
| 244 | * | |
| 245 | * We could probably include this in the normal ICBM parsing | |
| 246 | * code as channel 0x0003, however, since only the start | |
| 247 | * would be the same, we might as well do it here. | |
| 248 | * | |
| 249 | * General outline of this SNAC: | |
| 250 | * snac | |
| 251 | * cookie | |
| 252 | * channel id | |
| 253 | * tlvlist | |
| 254 | * unknown | |
| 255 | * source user info | |
| 256 | * name | |
| 257 | * evility | |
| 258 | * userinfo tlvs | |
| 259 | * online time | |
| 260 | * etc | |
| 261 | * message metatlv | |
| 262 | * message tlv | |
| 263 | * message string | |
| 264 | * possibly others | |
| 265 | * | |
| 266 | */ | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
267 | static int |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
268 | incomingim_ch3(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
| 13235 | 269 | { |
| 270 | int ret = 0, i; | |
| 271 | aim_rxcallback_t userfunc; | |
| 272 | aim_userinfo_t userinfo; | |
| 273 | guint8 cookie[8]; | |
| 274 | guint16 channel; | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
275 | GSList *tlvlist; |
| 13235 | 276 | char *msg = NULL; |
| 277 | int len = 0; | |
| 278 | char *encoding = NULL, *language = NULL; | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
279 | IcbmCookie *ck; |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
280 | aim_tlv_t *tlv; |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
281 | ByteStream tbs; |
| 13235 | 282 | |
| 283 | memset(&userinfo, 0, sizeof(aim_userinfo_t)); | |
| 284 | ||
| 285 | /* | |
| 286 | * Read ICBM Cookie. | |
| 287 | */ | |
| 288 | for (i = 0; i < 8; i++) | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
289 | cookie[i] = byte_stream_get8(bs); |
| 13235 | 290 | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
291 | if ((ck = aim_uncachecookie(od, cookie, AIM_COOKIETYPE_CHAT))) { |
|
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
|
292 | g_free(ck->data); |
|
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
|
293 | g_free(ck); |
| 13235 | 294 | } |
| 295 | ||
| 296 | /* | |
| 297 | * Channel ID | |
| 298 | * | |
| 299 | * Channel 0x0003 is used for chat messages. | |
| 300 | * | |
| 301 | */ | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
302 | channel = byte_stream_get16(bs); |
| 13235 | 303 | |
| 304 | if (channel != 0x0003) { | |
| 15884 | 305 | purple_debug_misc("oscar", "faim: chat_incoming: unknown channel! (0x%04x)\n", channel); |
| 13235 | 306 | return 0; |
| 307 | } | |
| 308 | ||
| 309 | /* | |
| 310 | * Start parsing TLVs right away. | |
| 311 | */ | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
312 | tlvlist = aim_tlvlist_read(bs); |
| 13235 | 313 | |
| 314 | /* | |
| 315 | * Type 0x0003: Source User Information | |
| 316 | */ | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
317 | tlv = aim_tlv_gettlv(tlvlist, 0x0003, 1); |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
318 | if (tlv != NULL) |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
319 | { |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
320 | byte_stream_init(&tbs, tlv->value, tlv->length); |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
321 | aim_info_extract(od, &tbs, &userinfo); |
| 13235 | 322 | } |
| 323 | ||
| 324 | /* | |
| 325 | * Type 0x0005: Message Block. Conains more TLVs. | |
| 326 | */ | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
327 | tlv = aim_tlv_gettlv(tlvlist, 0x0005, 1); |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
328 | if (tlv != NULL) |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
329 | { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
330 | GSList *inner_tlvlist; |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
331 | aim_tlv_t *inner_tlv; |
| 13235 | 332 | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
333 | byte_stream_init(&tbs, tlv->value, tlv->length); |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
334 | inner_tlvlist = aim_tlvlist_read(&tbs); |
| 13235 | 335 | |
| 336 | /* | |
| 337 | * Type 0x0001: Message. | |
| 338 | */ | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
339 | inner_tlv = aim_tlv_gettlv(inner_tlvlist, 0x0001, 1); |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
340 | if (inner_tlv != NULL) |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
341 | { |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
342 | len = inner_tlv->length; |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
343 | msg = aim_tlv_getvalue_as_string(inner_tlv); |
| 13235 | 344 | } |
| 345 | ||
| 346 | /* | |
| 347 | * Type 0x0002: Encoding. | |
| 348 | */ | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
349 | encoding = aim_tlv_getstr(inner_tlvlist, 0x0002, 1); |
| 13235 | 350 | |
| 351 | /* | |
| 352 | * Type 0x0003: Language. | |
| 353 | */ | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
354 | language = aim_tlv_getstr(inner_tlvlist, 0x0003, 1); |
| 13235 | 355 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
356 | aim_tlvlist_free(inner_tlvlist); |
| 13235 | 357 | } |
| 358 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
359 | if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
360 | ret = userfunc(od, conn, frame, &userinfo, len, msg, encoding, language); |
| 13235 | 361 | |
| 362 | aim_info_free(&userinfo); | |
|
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
|
363 | g_free(msg); |
|
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
|
364 | g_free(encoding); |
|
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
|
365 | g_free(language); |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
366 | aim_tlvlist_free(tlvlist); |
| 13235 | 367 | |
| 368 | return ret; | |
| 369 | } | |
| 370 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
371 | static int |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
372 | snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
| 13235 | 373 | { |
| 374 | if (snac->subtype == 0x0002) | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
375 | return infoupdate(od, conn, mod, frame, snac, bs); |
| 13235 | 376 | else if ((snac->subtype == 0x0003) || (snac->subtype == 0x0004)) |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
377 | return userlistchange(od, conn, mod, frame, snac, bs); |
| 13235 | 378 | else if (snac->subtype == 0x0006) |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
379 | return incomingim_ch3(od, conn, mod, frame, snac, bs); |
| 13235 | 380 | |
| 381 | return 0; | |
| 382 | } | |
| 383 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
384 | int |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13263
diff
changeset
|
385 | chat_modfirst(OscarData *od, aim_module_t *mod) |
| 13235 | 386 | { |
|
23456
66ab07770438
Replaced family_*'s magic numbers of FLAP families with the constants
Evan Schoenberg <evands@pidgin.im>
parents:
23004
diff
changeset
|
387 | mod->family = SNAC_FAMILY_CHAT; |
| 13235 | 388 | mod->version = 0x0001; |
| 389 | mod->toolid = 0x0010; | |
| 390 | mod->toolversion = 0x0629; | |
| 391 | mod->flags = 0; | |
| 392 | strncpy(mod->name, "chat", sizeof(mod->name)); | |
| 393 | mod->snachandler = snachandler; | |
| 394 | ||
| 395 | return 0; | |
| 396 | } |