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
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
1 | /* |
| 15884 | 2 | * Purple's oscar protocol plugin |
|
13235
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
3 | * This file is the legal property of its developers. |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
4 | * Please see the AUTHORS file distributed alongside this file. |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
5 | * |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
6 | * This library is free software; you can redistribute it and/or |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
7 | * modify it under the terms of the GNU Lesser General Public |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
8 | * License as published by the Free Software Foundation; either |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
9 | * version 2 of the License, or (at your option) any later version. |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
10 | * |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
11 | * This library is distributed in the hope that it will be useful, |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
14 | * Lesser General Public License for more details. |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
15 | * |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
16 | * You should have received a copy of the GNU Lesser General Public |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
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:
18952
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
13235
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
19 | */ |
| 2086 | 20 | |
|
13235
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
21 | #include "oscar.h" |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
22 | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
23 | static aim_tlv_t * |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
24 | createtlv(guint16 type, guint16 length, guint8 *value) |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
25 | { |
|
7158
2bdbaa3a8468
[gaim-migrate @ 7725]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
26 | aim_tlv_t *ret; |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
27 | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
28 | ret = g_new(aim_tlv_t, 1); |
|
7158
2bdbaa3a8468
[gaim-migrate @ 7725]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
29 | ret->type = type; |
|
2bdbaa3a8468
[gaim-migrate @ 7725]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
30 | ret->length = length; |
|
2bdbaa3a8468
[gaim-migrate @ 7725]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
31 | ret->value = value; |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
32 | |
|
7158
2bdbaa3a8468
[gaim-migrate @ 7725]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
33 | return ret; |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
34 | } |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
35 | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
36 | static void |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
37 | freetlv(aim_tlv_t *oldtlv) |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
38 | { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
39 | g_free(oldtlv->value); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
40 | g_free(oldtlv); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
41 | } |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
42 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
43 | static GSList * |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
44 | aim_tlv_read(GSList *list, ByteStream *bs) |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
45 | { |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
46 | guint16 type, length; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
47 | aim_tlv_t *tlv; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
48 | |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
49 | type = byte_stream_get16(bs); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
50 | length = byte_stream_get16(bs); |
|
10986
92a91fb514f4
[gaim-migrate @ 12822]
Mark Doliner <markdoliner@pidgin.im>
parents:
9933
diff
changeset
|
51 | |
| 30668 | 52 | if (length > byte_stream_bytes_left(bs)) { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
53 | aim_tlvlist_free(list); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
54 | return NULL; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
55 | } |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
56 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
57 | tlv = createtlv(type, length, NULL); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
58 | if (tlv->length > 0) { |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
59 | tlv->value = byte_stream_getraw(bs, length); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
60 | if (!tlv->value) { |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
61 | freetlv(tlv); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
62 | aim_tlvlist_free(list); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
63 | return NULL; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
64 | } |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
65 | } |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
66 | |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
67 | return g_slist_prepend(list, tlv); |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
68 | } |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
69 | |
| 2086 | 70 | /** |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
71 | * Read a TLV chain from a buffer. |
| 2086 | 72 | * |
| 73 | * Reads and parses a series of TLV patterns from a data buffer; the | |
| 74 | * returned structure is manipulatable with the rest of the TLV | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
75 | * routines. When done with a TLV chain, aim_tlvlist_free() should |
| 2086 | 76 | * be called to free the dynamic substructures. |
| 77 | * | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
78 | * TODO: There should be a flag setable here to have the tlvlist contain |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
79 | * bstream references, so that at least the ->value portion of each |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
80 | * element doesn't need to be malloc/memcpy'd. This could prove to be |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8225
diff
changeset
|
81 | * just as efficient as the in-place TLV parsing used in a couple places |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
82 | * in libfaim. |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
83 | * |
|
7158
2bdbaa3a8468
[gaim-migrate @ 7725]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
84 | * @param bs Input bstream |
|
8790
3d6d2e2f6296
[gaim-migrate @ 9552]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8735
diff
changeset
|
85 | * @return Return the TLV chain read |
| 2086 | 86 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
87 | GSList *aim_tlvlist_read(ByteStream *bs) |
| 2086 | 88 | { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
89 | GSList *list = NULL; |
|
10986
92a91fb514f4
[gaim-migrate @ 12822]
Mark Doliner <markdoliner@pidgin.im>
parents:
9933
diff
changeset
|
90 | |
| 30668 | 91 | while (byte_stream_bytes_left(bs) > 0) { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
92 | list = aim_tlv_read(list, bs); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
93 | if (list == NULL) |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
94 | return NULL; |
| 2086 | 95 | } |
| 96 | ||
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
97 | return g_slist_reverse(list); |
| 2086 | 98 | } |
| 99 | ||
| 100 | /** | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
101 | * Read a TLV chain from a buffer. |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
102 | * |
|
3952
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3912
diff
changeset
|
103 | * Reads and parses a series of TLV patterns from a data buffer; the |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3912
diff
changeset
|
104 | * returned structure is manipulatable with the rest of the TLV |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
105 | * routines. When done with a TLV chain, aim_tlvlist_free() should |
|
3952
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3912
diff
changeset
|
106 | * be called to free the dynamic substructures. |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3912
diff
changeset
|
107 | * |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
108 | * TODO: There should be a flag setable here to have the tlvlist contain |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
109 | * bstream references, so that at least the ->value portion of each |
|
3952
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3912
diff
changeset
|
110 | * element doesn't need to be malloc/memcpy'd. This could prove to be |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8225
diff
changeset
|
111 | * just as efficient as the in-place TLV parsing used in a couple places |
|
3952
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3912
diff
changeset
|
112 | * in libfaim. |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3912
diff
changeset
|
113 | * |
|
7158
2bdbaa3a8468
[gaim-migrate @ 7725]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
114 | * @param bs Input bstream |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
115 | * @param num The max number of TLVs that will be read, or -1 if unlimited. |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
116 | * There are a number of places where you want to read in a tlvchain, |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
117 | * but the chain is not at the end of the SNAC, and the chain is |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8225
diff
changeset
|
118 | * preceded by the number of TLVs. So you can limit that with this. |
|
8790
3d6d2e2f6296
[gaim-migrate @ 9552]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8735
diff
changeset
|
119 | * @return Return the TLV chain read |
|
3952
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3912
diff
changeset
|
120 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
121 | GSList *aim_tlvlist_readnum(ByteStream *bs, guint16 num) |
|
3952
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3912
diff
changeset
|
122 | { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
123 | GSList *list = NULL; |
|
4317
f3f135811a70
[gaim-migrate @ 4571]
Mark Doliner <markdoliner@pidgin.im>
parents:
4230
diff
changeset
|
124 | |
| 30668 | 125 | while ((byte_stream_bytes_left(bs) > 0) && (num != 0)) { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
126 | list = aim_tlv_read(list, bs); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
127 | if (list == NULL) |
|
3952
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3912
diff
changeset
|
128 | return NULL; |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
129 | num--; |
|
3952
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3912
diff
changeset
|
130 | } |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3912
diff
changeset
|
131 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
132 | return g_slist_reverse(list); |
|
3952
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3912
diff
changeset
|
133 | } |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3912
diff
changeset
|
134 | |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3912
diff
changeset
|
135 | /** |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
136 | * Read a TLV chain from a buffer. |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
137 | * |
|
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
138 | * Reads and parses a series of TLV patterns from a data buffer; the |
|
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
139 | * returned structure is manipulatable with the rest of the TLV |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
140 | * routines. When done with a TLV chain, aim_tlvlist_free() should |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
141 | * be called to free the dynamic substructures. |
|
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
142 | * |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
143 | * TODO: There should be a flag setable here to have the tlvlist contain |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
144 | * bstream references, so that at least the ->value portion of each |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
145 | * element doesn't need to be malloc/memcpy'd. This could prove to be |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8225
diff
changeset
|
146 | * just as efficient as the in-place TLV parsing used in a couple places |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
147 | * in libfaim. |
|
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
148 | * |
|
7158
2bdbaa3a8468
[gaim-migrate @ 7725]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
149 | * @param bs Input bstream |
|
2bdbaa3a8468
[gaim-migrate @ 7725]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
150 | * @param len The max length in bytes that will be read. |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
151 | * There are a number of places where you want to read in a tlvchain, |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
152 | * but the chain is not at the end of the SNAC, and the chain is |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8225
diff
changeset
|
153 | * preceded by the length of the TLVs. So you can limit that with this. |
|
8790
3d6d2e2f6296
[gaim-migrate @ 9552]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8735
diff
changeset
|
154 | * @return Return the TLV chain read |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
155 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
156 | GSList *aim_tlvlist_readlen(ByteStream *bs, guint16 len) |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
157 | { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
158 | GSList *list = NULL; |
|
4317
f3f135811a70
[gaim-migrate @ 4571]
Mark Doliner <markdoliner@pidgin.im>
parents:
4230
diff
changeset
|
159 | |
| 30668 | 160 | while ((byte_stream_bytes_left(bs) > 0) && (len > 0)) { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
161 | list = aim_tlv_read(list, bs); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
162 | if (list == NULL) |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
163 | return NULL; |
|
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
164 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
165 | len -= 2 + 2 + ((aim_tlv_t *)list->data)->length; |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
166 | } |
|
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
167 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
168 | return g_slist_reverse(list); |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
169 | } |
|
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
170 | |
|
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
171 | /** |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
172 | * Duplicate a TLV chain. |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8225
diff
changeset
|
173 | * This is pretty self explanatory. |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
174 | * |
|
7158
2bdbaa3a8468
[gaim-migrate @ 7725]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
175 | * @param orig The TLV chain you want to make a copy of. |
|
2bdbaa3a8468
[gaim-migrate @ 7725]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
176 | * @return A newly allocated TLV chain. |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
177 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
178 | GSList *aim_tlvlist_copy(GSList *orig) |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
179 | { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
180 | GSList *new = NULL; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
181 | aim_tlv_t *tlv; |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
182 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
183 | while (orig != NULL) { |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
184 | tlv = orig->data; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
185 | aim_tlvlist_add_raw(&new, tlv->type, tlv->length, tlv->value); |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
186 | orig = orig->next; |
|
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
187 | } |
|
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
188 | |
|
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
189 | return new; |
|
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
190 | } |
|
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
191 | |
|
6101
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
192 | /* |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
193 | * Compare two TLV lists for equality. This probably is not the most |
|
6101
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
194 | * efficient way to do this. |
|
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
195 | * |
|
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
196 | * @param one One of the TLV chains to compare. |
|
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
197 | * @param two The other TLV chain to compare. |
|
8790
3d6d2e2f6296
[gaim-migrate @ 9552]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8735
diff
changeset
|
198 | * @return Return 0 if the lists are the same, return 1 if they are different. |
|
6101
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
199 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
200 | int aim_tlvlist_cmp(GSList *one, GSList *two) |
|
6101
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
201 | { |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
202 | ByteStream bs1, bs2; |
|
6101
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
203 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
204 | if (aim_tlvlist_size(one) != aim_tlvlist_size(two)) |
|
6101
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
205 | return 1; |
|
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
206 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
207 | byte_stream_new(&bs1, aim_tlvlist_size(one)); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
208 | byte_stream_new(&bs2, aim_tlvlist_size(two)); |
|
6101
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
209 | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
210 | aim_tlvlist_write(&bs1, &one); |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
211 | aim_tlvlist_write(&bs2, &two); |
|
6101
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
212 | |
|
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
213 | if (memcmp(bs1.data, bs2.data, bs1.len)) { |
|
22861
76cb58c0c40a
Used byte_stream_destroy(), added in 2b0e247173b206213210577c194020c78c864474,
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
214 | byte_stream_destroy(&bs1); |
|
76cb58c0c40a
Used byte_stream_destroy(), added in 2b0e247173b206213210577c194020c78c864474,
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
215 | byte_stream_destroy(&bs2); |
|
6101
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
216 | return 1; |
|
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
217 | } |
|
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
218 | |
|
22861
76cb58c0c40a
Used byte_stream_destroy(), added in 2b0e247173b206213210577c194020c78c864474,
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
219 | byte_stream_destroy(&bs1); |
|
76cb58c0c40a
Used byte_stream_destroy(), added in 2b0e247173b206213210577c194020c78c864474,
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
220 | byte_stream_destroy(&bs2); |
|
6101
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
221 | |
|
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
222 | return 0; |
|
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
223 | } |
|
c3762fa398c4
[gaim-migrate @ 6560]
Mark Doliner <markdoliner@pidgin.im>
parents:
4617
diff
changeset
|
224 | |
|
4230
b5393db78439
[gaim-migrate @ 4475]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
225 | /** |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
226 | * Free a TLV chain structure |
| 2086 | 227 | * |
| 228 | * Walks the list of TLVs in the passed TLV chain and | |
| 229 | * frees each one. Note that any references to this data | |
| 230 | * should be removed before calling this. | |
| 231 | * | |
|
8790
3d6d2e2f6296
[gaim-migrate @ 9552]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8735
diff
changeset
|
232 | * @param list Chain to be freed |
| 2086 | 233 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
234 | void aim_tlvlist_free(GSList *list) |
| 2086 | 235 | { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
236 | while (list != NULL) |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
237 | { |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
238 | freetlv(list->data); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
239 | list = g_slist_delete_link(list, list); |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
240 | } |
| 2086 | 241 | } |
| 242 | ||
| 243 | /** | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
244 | * Count the number of TLVs in a chain. |
| 2086 | 245 | * |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
246 | * @param list Chain to be counted. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
247 | * @return The number of TLVs stored in the passed chain. |
| 2086 | 248 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
249 | int aim_tlvlist_count(GSList *list) |
| 2086 | 250 | { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
251 | GSList *cur; |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
252 | int count; |
| 2086 | 253 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
254 | if (list == NULL) |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
255 | return 0; |
| 2086 | 256 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
257 | for (cur = list, count = 0; cur; cur = cur->next) |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
258 | count++; |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
259 | |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
260 | return count; |
| 2086 | 261 | } |
| 262 | ||
| 263 | /** | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
264 | * Count the number of bytes in a TLV chain. |
| 2086 | 265 | * |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
266 | * @param list Chain to be sized |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
267 | * @return The number of bytes that would be needed to |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
268 | * write the passed TLV chain to a data buffer. |
| 2086 | 269 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
270 | int aim_tlvlist_size(GSList *list) |
| 2086 | 271 | { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
272 | GSList *cur; |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
273 | int size; |
| 2086 | 274 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
275 | if (list == NULL) |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
276 | return 0; |
| 2086 | 277 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
278 | for (cur = list, size = 0; cur; cur = cur->next) |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
279 | size += (4 + ((aim_tlv_t *)cur->data)->length); |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
280 | |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
281 | return size; |
| 2086 | 282 | } |
| 283 | ||
| 284 | /** | |
| 285 | * Adds the passed string as a TLV element of the passed type | |
| 286 | * to the TLV chain. | |
| 287 | * | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
288 | * @param list Desination chain (%NULL pointer if empty). |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
289 | * @param type TLV type. |
|
8790
3d6d2e2f6296
[gaim-migrate @ 9552]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8735
diff
changeset
|
290 | * @param length Length of string to add (not including %NULL). |
|
3d6d2e2f6296
[gaim-migrate @ 9552]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8735
diff
changeset
|
291 | * @param value String to add. |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8225
diff
changeset
|
292 | * @return The size of the value added. |
| 2086 | 293 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
294 | int aim_tlvlist_add_raw(GSList **list, const guint16 type, const guint16 length, const guint8 *value) |
| 2086 | 295 | { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
296 | aim_tlv_t *tlv; |
| 2086 | 297 | |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
298 | if (list == NULL) |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
299 | return 0; |
| 2086 | 300 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
301 | tlv = createtlv(type, length, NULL); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
302 | if (tlv->length > 0) |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
303 | tlv->value = g_memdup(value, length); |
| 2086 | 304 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
305 | *list = g_slist_append(*list, tlv); |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
306 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
307 | return tlv->length; |
| 2086 | 308 | } |
| 309 | ||
| 310 | /** | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
311 | * Add a one byte integer to a TLV chain. |
|
2821
f1ab7f03bdad
[gaim-migrate @ 2834]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2421
diff
changeset
|
312 | * |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
313 | * @param list Destination chain. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
314 | * @param type TLV type to add. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
315 | * @param value Value to add. |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8225
diff
changeset
|
316 | * @return The size of the value added. |
|
2821
f1ab7f03bdad
[gaim-migrate @ 2834]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2421
diff
changeset
|
317 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
318 | int aim_tlvlist_add_8(GSList **list, const guint16 type, const guint8 value) |
|
2821
f1ab7f03bdad
[gaim-migrate @ 2834]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2421
diff
changeset
|
319 | { |
|
13235
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
320 | guint8 v8[1]; |
|
2821
f1ab7f03bdad
[gaim-migrate @ 2834]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2421
diff
changeset
|
321 | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
322 | aimutil_put8(v8, value); |
|
2821
f1ab7f03bdad
[gaim-migrate @ 2834]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2421
diff
changeset
|
323 | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
324 | return aim_tlvlist_add_raw(list, type, 1, v8); |
|
2821
f1ab7f03bdad
[gaim-migrate @ 2834]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2421
diff
changeset
|
325 | } |
|
f1ab7f03bdad
[gaim-migrate @ 2834]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2421
diff
changeset
|
326 | |
|
f1ab7f03bdad
[gaim-migrate @ 2834]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2421
diff
changeset
|
327 | /** |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
328 | * Add a two byte integer to a TLV chain. |
| 2086 | 329 | * |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
330 | * @param list Destination chain. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
331 | * @param type TLV type to add. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
332 | * @param value Value to add. |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8225
diff
changeset
|
333 | * @return The size of the value added. |
| 2086 | 334 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
335 | int aim_tlvlist_add_16(GSList **list, const guint16 type, const guint16 value) |
| 2086 | 336 | { |
|
13235
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
337 | guint8 v16[2]; |
| 2086 | 338 | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
339 | aimutil_put16(v16, value); |
| 2086 | 340 | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
341 | return aim_tlvlist_add_raw(list, type, 2, v16); |
| 2086 | 342 | } |
| 343 | ||
| 344 | /** | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
345 | * Add a four byte integer to a TLV chain. |
| 2086 | 346 | * |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
347 | * @param list Destination chain. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
348 | * @param type TLV type to add. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
349 | * @param value Value to add. |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8225
diff
changeset
|
350 | * @return The size of the value added. |
| 2086 | 351 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
352 | int aim_tlvlist_add_32(GSList **list, const guint16 type, const guint32 value) |
| 2086 | 353 | { |
|
13235
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
354 | guint8 v32[4]; |
| 2086 | 355 | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
356 | aimutil_put32(v32, value); |
| 2086 | 357 | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
358 | return aim_tlvlist_add_raw(list, type, 4, v32); |
| 2086 | 359 | } |
| 360 | ||
| 361 | /** | |
|
10986
92a91fb514f4
[gaim-migrate @ 12822]
Mark Doliner <markdoliner@pidgin.im>
parents:
9933
diff
changeset
|
362 | * Add a string to a TLV chain. |
|
92a91fb514f4
[gaim-migrate @ 12822]
Mark Doliner <markdoliner@pidgin.im>
parents:
9933
diff
changeset
|
363 | * |
|
92a91fb514f4
[gaim-migrate @ 12822]
Mark Doliner <markdoliner@pidgin.im>
parents:
9933
diff
changeset
|
364 | * @param list Destination chain. |
|
92a91fb514f4
[gaim-migrate @ 12822]
Mark Doliner <markdoliner@pidgin.im>
parents:
9933
diff
changeset
|
365 | * @param type TLV type to add. |
|
92a91fb514f4
[gaim-migrate @ 12822]
Mark Doliner <markdoliner@pidgin.im>
parents:
9933
diff
changeset
|
366 | * @param value Value to add. |
|
92a91fb514f4
[gaim-migrate @ 12822]
Mark Doliner <markdoliner@pidgin.im>
parents:
9933
diff
changeset
|
367 | * @return The size of the value added. |
|
92a91fb514f4
[gaim-migrate @ 12822]
Mark Doliner <markdoliner@pidgin.im>
parents:
9933
diff
changeset
|
368 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
369 | int aim_tlvlist_add_str(GSList **list, const guint16 type, const char *value) |
|
10986
92a91fb514f4
[gaim-migrate @ 12822]
Mark Doliner <markdoliner@pidgin.im>
parents:
9933
diff
changeset
|
370 | { |
|
13235
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
371 | return aim_tlvlist_add_raw(list, type, strlen(value), (guint8 *)value); |
|
10986
92a91fb514f4
[gaim-migrate @ 12822]
Mark Doliner <markdoliner@pidgin.im>
parents:
9933
diff
changeset
|
372 | } |
|
92a91fb514f4
[gaim-migrate @ 12822]
Mark Doliner <markdoliner@pidgin.im>
parents:
9933
diff
changeset
|
373 | |
|
30676
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
374 | static int |
|
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
375 | count_caps(guint64 caps) |
|
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
376 | { |
|
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
377 | int set_bits = 0; |
|
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
378 | while (caps) { |
|
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
379 | set_bits += caps & 1; |
|
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
380 | caps >>= 1; |
|
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
381 | } |
|
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
382 | return set_bits; |
|
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
383 | } |
|
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
384 | |
|
10986
92a91fb514f4
[gaim-migrate @ 12822]
Mark Doliner <markdoliner@pidgin.im>
parents:
9933
diff
changeset
|
385 | /** |
| 2086 | 386 | * Adds a block of capability blocks to a TLV chain. The bitfield |
| 387 | * passed in should be a bitwise %OR of any of the %AIM_CAPS constants: | |
| 388 | * | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
389 | * %OSCAR_CAPABILITY_BUDDYICON Supports Buddy Icons |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
390 | * %OSCAR_CAPABILITY_TALK Supports Voice Chat |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
391 | * %OSCAR_CAPABILITY_IMIMAGE Supports DirectIM/IMImage |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
392 | * %OSCAR_CAPABILITY_CHAT Supports Chat |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
393 | * %OSCAR_CAPABILITY_GETFILE Supports Get File functions |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
394 | * %OSCAR_CAPABILITY_SENDFILE Supports Send File functions |
| 2086 | 395 | * |
|
7158
2bdbaa3a8468
[gaim-migrate @ 7725]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
396 | * @param list Destination chain |
|
2bdbaa3a8468
[gaim-migrate @ 7725]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
397 | * @param type TLV type to add |
|
2bdbaa3a8468
[gaim-migrate @ 7725]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
398 | * @param caps Bitfield of capability flags to send |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8225
diff
changeset
|
399 | * @return The size of the value added. |
| 2086 | 400 | */ |
|
29889
7264be912028
Change the oscar capabilities variable to be a guint64 everywhere instead
Mark Doliner <markdoliner@pidgin.im>
parents:
24912
diff
changeset
|
401 | int aim_tlvlist_add_caps(GSList **list, const guint16 type, const guint64 caps, const char *mood) |
| 2086 | 402 | { |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
403 | ByteStream bs; |
|
30676
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
404 | guint32 bs_size; |
|
24625
4082cd694acb
This patch comes from the combined work of contributors minstrel, NightFox,
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22861
diff
changeset
|
405 | guint8 *data; |
| 2086 | 406 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
407 | if (caps == 0) |
|
2421
009ae3cf0e83
[gaim-migrate @ 2434]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2270
diff
changeset
|
408 | return 0; /* nothing there anyway */ |
|
009ae3cf0e83
[gaim-migrate @ 2434]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2270
diff
changeset
|
409 | |
|
30676
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
410 | data = icq_get_custom_icon_data(mood); |
|
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
411 | bs_size = 16*(count_caps(caps) + (data != NULL ? 1 : 0)); |
| 2086 | 412 | |
|
30676
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
413 | byte_stream_new(&bs, bs_size); |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
414 | byte_stream_putcaps(&bs, caps); |
|
30676
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
415 | |
|
24625
4082cd694acb
This patch comes from the combined work of contributors minstrel, NightFox,
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22861
diff
changeset
|
416 | /* adding of custom icon GUID */ |
|
24907
13118548c74c
Add a PURPLE_STATUS_MOOD primitive and change ICQ to use it.
Richard Laager <rlaager@pidgin.im>
parents:
24625
diff
changeset
|
417 | if (data != NULL) |
|
24625
4082cd694acb
This patch comes from the combined work of contributors minstrel, NightFox,
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22861
diff
changeset
|
418 | byte_stream_putraw(&bs, data, 16); |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
419 | |
|
30676
e6e19d26597c
Fixes #12044. We send a dummy packet with DC version = 8 to make
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
420 | return aim_tlvlist_add_raw(list, type, byte_stream_curpos(&bs), bs.data); |
| 2086 | 421 | } |
| 422 | ||
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
423 | /** |
|
8225
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
424 | * Adds the given chatroom info to a TLV chain. |
|
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
425 | * |
|
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
426 | * @param list Destination chain. |
|
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
427 | * @param type TLV type to add. |
|
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
428 | * @param roomname The name of the chat. |
|
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
429 | * @param instance The instance. |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8225
diff
changeset
|
430 | * @return The size of the value added. |
|
8225
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
431 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
432 | int aim_tlvlist_add_chatroom(GSList **list, guint16 type, guint16 exchange, const char *roomname, guint16 instance) |
|
8225
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
433 | { |
|
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
434 | int len; |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
435 | ByteStream bs; |
|
8225
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
436 | |
|
15151
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
437 | byte_stream_new(&bs, 2 + 1 + strlen(roomname) + 2); |
|
8225
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
438 | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
439 | byte_stream_put16(&bs, exchange); |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
440 | byte_stream_put8(&bs, strlen(roomname)); |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
441 | byte_stream_putstr(&bs, roomname); |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
442 | byte_stream_put16(&bs, instance); |
|
8225
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
443 | |
|
15151
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
444 | len = aim_tlvlist_add_raw(list, type, byte_stream_curpos(&bs), bs.data); |
|
8225
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
445 | |
|
22861
76cb58c0c40a
Used byte_stream_destroy(), added in 2b0e247173b206213210577c194020c78c864474,
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
446 | byte_stream_destroy(&bs); |
|
8225
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
447 | |
|
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
448 | return len; |
|
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
449 | } |
|
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
450 | |
|
4ef47db8c9bc
[gaim-migrate @ 8948]
Mark Doliner <markdoliner@pidgin.im>
parents:
8092
diff
changeset
|
451 | /** |
| 2086 | 452 | * Adds a TLV with a zero length to a TLV chain. |
| 453 | * | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
454 | * @param list Destination chain. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
455 | * @param type TLV type to add. |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8225
diff
changeset
|
456 | * @return The size of the value added. |
| 2086 | 457 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
458 | int aim_tlvlist_add_noval(GSList **list, const guint16 type) |
| 2086 | 459 | { |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
460 | return aim_tlvlist_add_raw(list, type, 0, NULL); |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
461 | } |
| 2086 | 462 | |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
463 | /* |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
464 | * Note that the inner TLV chain will not be modifiable as a tlvchain once |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
465 | * it is written using this. Or rather, it can be, but updates won't be |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
466 | * made to this. |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
467 | * |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
468 | * TODO: Should probably support sublists for real. |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
469 | * |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
470 | * This is so neat. |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
471 | * |
|
8790
3d6d2e2f6296
[gaim-migrate @ 9552]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8735
diff
changeset
|
472 | * @param list Destination chain. |
|
3d6d2e2f6296
[gaim-migrate @ 9552]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8735
diff
changeset
|
473 | * @param type TLV type to add. |
|
3d6d2e2f6296
[gaim-migrate @ 9552]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8735
diff
changeset
|
474 | * @param t1 The TLV chain you want to write. |
|
8794
4c2c247ef665
[gaim-migrate @ 9556]
Mark Doliner <markdoliner@pidgin.im>
parents:
8790
diff
changeset
|
475 | * @return The number of bytes written to the destination TLV chain. |
|
4c2c247ef665
[gaim-migrate @ 9556]
Mark Doliner <markdoliner@pidgin.im>
parents:
8790
diff
changeset
|
476 | * 0 is returned if there was an error or if the destination |
|
4c2c247ef665
[gaim-migrate @ 9556]
Mark Doliner <markdoliner@pidgin.im>
parents:
8790
diff
changeset
|
477 | * TLV chain has length 0. |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
478 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
479 | int aim_tlvlist_add_frozentlvlist(GSList **list, guint16 type, GSList **tlvlist) |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
480 | { |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
481 | int buflen; |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
482 | ByteStream bs; |
| 2086 | 483 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
484 | buflen = aim_tlvlist_size(*tlvlist); |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
485 | |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
486 | if (buflen <= 0) |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
487 | return 0; |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
488 | |
|
15151
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
489 | byte_stream_new(&bs, buflen); |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
490 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
491 | aim_tlvlist_write(&bs, tlvlist); |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
492 | |
|
15151
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
493 | aim_tlvlist_add_raw(list, type, byte_stream_curpos(&bs), bs.data); |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
494 | |
|
22861
76cb58c0c40a
Used byte_stream_destroy(), added in 2b0e247173b206213210577c194020c78c864474,
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
495 | byte_stream_destroy(&bs); |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
496 | |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
497 | return buflen; |
| 2086 | 498 | } |
| 499 | ||
| 500 | /** | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
501 | * Substitute a TLV of a given type with a new TLV of the same type. If |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
502 | * you attempt to replace a TLV that does not exist, this function will |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
503 | * just add a new TLV as if you called aim_tlvlist_add_raw(). |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
504 | * |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
505 | * @param list Desination chain (%NULL pointer if empty). |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
506 | * @param type TLV type. |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
507 | * @param length Length of string to add (not including %NULL). |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
508 | * @param value String to add. |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
509 | * @return The length of the TLV. |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
510 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
511 | int aim_tlvlist_replace_raw(GSList **list, const guint16 type, const guint16 length, const guint8 *value) |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
512 | { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
513 | GSList *cur; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
514 | aim_tlv_t *tlv; |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
515 | |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
516 | if (list == NULL) |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
517 | return 0; |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
518 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
519 | for (cur = *list; cur != NULL; cur = cur->next) |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
520 | { |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
521 | tlv = cur->data; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
522 | if (tlv->type == type) |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
523 | break; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
524 | } |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
525 | |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
526 | if (cur == NULL) |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
527 | /* TLV does not exist, so add a new one */ |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
528 | return aim_tlvlist_add_raw(list, type, length, value); |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
529 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
530 | g_free(tlv->value); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
531 | tlv->length = length; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
532 | if (tlv->length > 0) { |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
533 | tlv->value = g_memdup(value, length); |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
534 | } else |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
535 | tlv->value = NULL; |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
536 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
537 | return tlv->length; |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
538 | } |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
539 | |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
540 | /** |
|
11159
76ef02141bcb
[gaim-migrate @ 13246]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
541 | * Substitute a TLV of a given type with a new TLV of the same type. If |
|
76ef02141bcb
[gaim-migrate @ 13246]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
542 | * you attempt to replace a TLV that does not exist, this function will |
|
10993
8c992e277e86
[gaim-migrate @ 12831]
Mark Doliner <markdoliner@pidgin.im>
parents:
10991
diff
changeset
|
543 | * just add a new TLV as if you called aim_tlvlist_add_str(). |
|
8c992e277e86
[gaim-migrate @ 12831]
Mark Doliner <markdoliner@pidgin.im>
parents:
10991
diff
changeset
|
544 | * |
|
8c992e277e86
[gaim-migrate @ 12831]
Mark Doliner <markdoliner@pidgin.im>
parents:
10991
diff
changeset
|
545 | * @param list Desination chain (%NULL pointer if empty). |
|
8c992e277e86
[gaim-migrate @ 12831]
Mark Doliner <markdoliner@pidgin.im>
parents:
10991
diff
changeset
|
546 | * @param type TLV type. |
|
8c992e277e86
[gaim-migrate @ 12831]
Mark Doliner <markdoliner@pidgin.im>
parents:
10991
diff
changeset
|
547 | * @param str String to add. |
|
8c992e277e86
[gaim-migrate @ 12831]
Mark Doliner <markdoliner@pidgin.im>
parents:
10991
diff
changeset
|
548 | * @return The length of the TLV. |
|
8c992e277e86
[gaim-migrate @ 12831]
Mark Doliner <markdoliner@pidgin.im>
parents:
10991
diff
changeset
|
549 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
550 | int aim_tlvlist_replace_str(GSList **list, const guint16 type, const char *str) |
|
10993
8c992e277e86
[gaim-migrate @ 12831]
Mark Doliner <markdoliner@pidgin.im>
parents:
10991
diff
changeset
|
551 | { |
|
11159
76ef02141bcb
[gaim-migrate @ 13246]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
552 | return aim_tlvlist_replace_raw(list, type, strlen(str), (const guchar *)str); |
|
10993
8c992e277e86
[gaim-migrate @ 12831]
Mark Doliner <markdoliner@pidgin.im>
parents:
10991
diff
changeset
|
553 | } |
|
8c992e277e86
[gaim-migrate @ 12831]
Mark Doliner <markdoliner@pidgin.im>
parents:
10991
diff
changeset
|
554 | |
|
8c992e277e86
[gaim-migrate @ 12831]
Mark Doliner <markdoliner@pidgin.im>
parents:
10991
diff
changeset
|
555 | /** |
|
11159
76ef02141bcb
[gaim-migrate @ 13246]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
556 | * Substitute a TLV of a given type with a new TLV of the same type. If |
|
76ef02141bcb
[gaim-migrate @ 13246]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
557 | * you attempt to replace a TLV that does not exist, this function will |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
558 | * just add a new TLV as if you called aim_tlvlist_add_raw(). |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
559 | * |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
560 | * @param list Desination chain (%NULL pointer if empty). |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
561 | * @param type TLV type. |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
562 | * @return The length of the TLV. |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
563 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
564 | int aim_tlvlist_replace_noval(GSList **list, const guint16 type) |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
565 | { |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
566 | return aim_tlvlist_replace_raw(list, type, 0, NULL); |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
567 | } |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
568 | |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
569 | /** |
|
11159
76ef02141bcb
[gaim-migrate @ 13246]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
570 | * Substitute a TLV of a given type with a new TLV of the same type. If |
|
76ef02141bcb
[gaim-migrate @ 13246]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
571 | * you attempt to replace a TLV that does not exist, this function will |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
572 | * just add a new TLV as if you called aim_tlvlist_add_raw(). |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
573 | * |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
574 | * @param list Desination chain (%NULL pointer if empty). |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
575 | * @param type TLV type. |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
576 | * @param value 8 bit value to add. |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
577 | * @return The length of the TLV. |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
578 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
579 | int aim_tlvlist_replace_8(GSList **list, const guint16 type, const guint8 value) |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
580 | { |
|
13235
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
581 | guint8 v8[1]; |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
582 | |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
583 | aimutil_put8(v8, value); |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
584 | |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
585 | return aim_tlvlist_replace_raw(list, type, 1, v8); |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
586 | } |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
587 | |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
588 | /** |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
589 | * Substitute a TLV of a given type with a new TLV of the same type. If |
|
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
590 | * you attempt to replace a TLV that does not exist, this function will |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
591 | * just add a new TLV as if you called aim_tlvlist_add_raw(). |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
592 | * |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
593 | * @param list Desination chain (%NULL pointer if empty). |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
594 | * @param type TLV type. |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
595 | * @param value 32 bit value to add. |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
596 | * @return The length of the TLV. |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
597 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
598 | int aim_tlvlist_replace_32(GSList **list, const guint16 type, const guint32 value) |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
599 | { |
|
13235
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
11285
diff
changeset
|
600 | guint8 v32[4]; |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
601 | |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
602 | aimutil_put32(v32, value); |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
603 | |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
604 | return aim_tlvlist_replace_raw(list, type, 4, v32); |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
605 | } |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
606 | |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
607 | /** |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
608 | * Remove all TLVs of a given type. If you attempt to remove a TLV |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
609 | * that does not exist, nothing happens. |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
610 | * |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
611 | * @param list Desination chain (%NULL pointer if empty). |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
612 | * @param type TLV type. |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
613 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
614 | void aim_tlvlist_remove(GSList **list, const guint16 type) |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
615 | { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
616 | GSList *cur, *next; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
617 | aim_tlv_t *tlv; |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
618 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
619 | if (list == NULL || *list == NULL) |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
620 | return; |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
621 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
622 | cur = *list; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
623 | while (cur != NULL) |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
624 | { |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
625 | tlv = cur->data; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
626 | next = cur->next; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
627 | |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
628 | if (tlv->type == type) |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
629 | { |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
630 | /* Delete this TLV */ |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
631 | *list = g_slist_delete_link(*list, cur); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
632 | g_free(tlv->value); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
633 | g_free(tlv); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
634 | } |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
635 | |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
636 | cur = next; |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
637 | } |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
638 | } |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
639 | |
|
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
640 | /** |
|
8794
4c2c247ef665
[gaim-migrate @ 9556]
Mark Doliner <markdoliner@pidgin.im>
parents:
8790
diff
changeset
|
641 | * Write a TLV chain into a data buffer. |
| 2086 | 642 | * |
| 643 | * Copies a TLV chain into a raw data buffer, writing only the number | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
644 | * of bytes specified. This operation does not free the chain; |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
645 | * aim_tlvlist_free() must still be called to free up the memory used |
| 2086 | 646 | * by the chain structures. |
| 647 | * | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
648 | * TODO: Clean this up, make better use of bstreams |
|
8790
3d6d2e2f6296
[gaim-migrate @ 9552]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8735
diff
changeset
|
649 | * |
|
3d6d2e2f6296
[gaim-migrate @ 9552]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8735
diff
changeset
|
650 | * @param bs Input bstream |
|
3d6d2e2f6296
[gaim-migrate @ 9552]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8735
diff
changeset
|
651 | * @param list Source TLV chain |
|
8794
4c2c247ef665
[gaim-migrate @ 9556]
Mark Doliner <markdoliner@pidgin.im>
parents:
8790
diff
changeset
|
652 | * @return Return 0 if the destination bstream is too small. |
| 2086 | 653 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
654 | int aim_tlvlist_write(ByteStream *bs, GSList **list) |
| 2086 | 655 | { |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
656 | int goodbuflen; |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
657 | GSList *cur; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
658 | aim_tlv_t *tlv; |
| 2086 | 659 | |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
660 | /* do an initial run to test total length */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
661 | goodbuflen = aim_tlvlist_size(*list); |
| 2086 | 662 | |
| 30668 | 663 | if (goodbuflen > byte_stream_bytes_left(bs)) |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
664 | return 0; /* not enough buffer */ |
| 2086 | 665 | |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
666 | /* do the real write-out */ |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
667 | for (cur = *list; cur; cur = cur->next) { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
668 | tlv = cur->data; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
669 | byte_stream_put16(bs, tlv->type); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
670 | byte_stream_put16(bs, tlv->length); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
671 | if (tlv->length > 0) |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
672 | byte_stream_putraw(bs, tlv->value, tlv->length); |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
673 | } |
| 2086 | 674 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
675 | return 1; /* TODO: This is a nonsensical return */ |
| 2086 | 676 | } |
| 677 | ||
| 678 | ||
| 679 | /** | |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
680 | * Grab the Nth TLV of type type in the TLV list list. |
| 2086 | 681 | * |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
682 | * Returns a pointer to an aim_tlv_t of the specified type; |
| 2086 | 683 | * %NULL on error. The @nth parameter is specified starting at %1. |
| 684 | * In most cases, there will be no more than one TLV of any type | |
| 685 | * in a chain. | |
| 686 | * | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
687 | * @param list Source chain. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
688 | * @param type Requested TLV type. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
689 | * @param nth Index of TLV of type to get. |
|
7166
70825074f830
[gaim-migrate @ 7733]
Mark Doliner <markdoliner@pidgin.im>
parents:
7158
diff
changeset
|
690 | * @return The TLV you were looking for, or NULL if one could not be found. |
| 2086 | 691 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
692 | aim_tlv_t *aim_tlv_gettlv(GSList *list, const guint16 type, const int nth) |
| 2086 | 693 | { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
694 | GSList *cur; |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
695 | aim_tlv_t *tlv; |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
696 | int i; |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
697 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
698 | for (cur = list, i = 0; cur != NULL; cur = cur->next) { |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
699 | tlv = cur->data; |
|
18876
8d8198f72306
I don't think this check is needed. If it is then it's because we're
Mark Doliner <markdoliner@pidgin.im>
parents:
17443
diff
changeset
|
700 | if (tlv->type == type) |
|
8d8198f72306
I don't think this check is needed. If it is then it's because we're
Mark Doliner <markdoliner@pidgin.im>
parents:
17443
diff
changeset
|
701 | i++; |
|
8d8198f72306
I don't think this check is needed. If it is then it's because we're
Mark Doliner <markdoliner@pidgin.im>
parents:
17443
diff
changeset
|
702 | if (i >= nth) |
|
8d8198f72306
I don't think this check is needed. If it is then it's because we're
Mark Doliner <markdoliner@pidgin.im>
parents:
17443
diff
changeset
|
703 | return tlv; |
| 2086 | 704 | } |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
705 | |
|
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
706 | return NULL; |
| 2086 | 707 | } |
| 708 | ||
| 709 | /** | |
|
9933
61bd3fadbfe6
[gaim-migrate @ 10825]
Dave West <kat@users.sourceforge.net>
parents:
8794
diff
changeset
|
710 | * Get the length of the data of the nth TLV in the given TLV chain. |
|
61bd3fadbfe6
[gaim-migrate @ 10825]
Dave West <kat@users.sourceforge.net>
parents:
8794
diff
changeset
|
711 | * |
|
61bd3fadbfe6
[gaim-migrate @ 10825]
Dave West <kat@users.sourceforge.net>
parents:
8794
diff
changeset
|
712 | * @param list Source chain. |
|
61bd3fadbfe6
[gaim-migrate @ 10825]
Dave West <kat@users.sourceforge.net>
parents:
8794
diff
changeset
|
713 | * @param type Requested TLV type. |
|
61bd3fadbfe6
[gaim-migrate @ 10825]
Dave West <kat@users.sourceforge.net>
parents:
8794
diff
changeset
|
714 | * @param nth Index of TLV of type to get. |
|
61bd3fadbfe6
[gaim-migrate @ 10825]
Dave West <kat@users.sourceforge.net>
parents:
8794
diff
changeset
|
715 | * @return The length of the data in this TLV, or -1 if the TLV could not be |
|
61bd3fadbfe6
[gaim-migrate @ 10825]
Dave West <kat@users.sourceforge.net>
parents:
8794
diff
changeset
|
716 | * found. Unless -1 is returned, this value will be 2 bytes. |
|
61bd3fadbfe6
[gaim-migrate @ 10825]
Dave West <kat@users.sourceforge.net>
parents:
8794
diff
changeset
|
717 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
718 | int aim_tlv_getlength(GSList *list, const guint16 type, const int nth) |
|
9933
61bd3fadbfe6
[gaim-migrate @ 10825]
Dave West <kat@users.sourceforge.net>
parents:
8794
diff
changeset
|
719 | { |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
720 | aim_tlv_t *tlv; |
|
9933
61bd3fadbfe6
[gaim-migrate @ 10825]
Dave West <kat@users.sourceforge.net>
parents:
8794
diff
changeset
|
721 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
722 | tlv = aim_tlv_gettlv(list, type, nth); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
723 | if (tlv == NULL) |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
724 | return -1; |
|
9933
61bd3fadbfe6
[gaim-migrate @ 10825]
Dave West <kat@users.sourceforge.net>
parents:
8794
diff
changeset
|
725 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
726 | return tlv->length; |
|
9933
61bd3fadbfe6
[gaim-migrate @ 10825]
Dave West <kat@users.sourceforge.net>
parents:
8794
diff
changeset
|
727 | } |
|
61bd3fadbfe6
[gaim-migrate @ 10825]
Dave West <kat@users.sourceforge.net>
parents:
8794
diff
changeset
|
728 | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
729 | char * |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
730 | aim_tlv_getvalue_as_string(aim_tlv_t *tlv) |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
731 | { |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
732 | char *ret; |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
733 | |
|
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
|
734 | ret = g_malloc(tlv->length + 1); |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
735 | memcpy(ret, tlv->value, tlv->length); |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
736 | ret[tlv->length] = '\0'; |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
737 | |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
738 | return ret; |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
739 | } |
|
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
740 | |
|
9933
61bd3fadbfe6
[gaim-migrate @ 10825]
Dave West <kat@users.sourceforge.net>
parents:
8794
diff
changeset
|
741 | /** |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
742 | * Retrieve the data from the nth TLV in the given TLV chain as a string. |
| 2086 | 743 | * |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
744 | * @param list Source TLV chain. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
745 | * @param type TLV type to search for. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
746 | * @param nth Index of TLV to return. |
|
11159
76ef02141bcb
[gaim-migrate @ 13246]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
747 | * @return The value of the TLV you were looking for, or NULL if one could |
|
76ef02141bcb
[gaim-migrate @ 13246]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
748 | * not be found. This is a dynamic buffer and must be freed by the |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
749 | * caller. |
| 2086 | 750 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
751 | char *aim_tlv_getstr(GSList *list, const guint16 type, const int nth) |
| 2086 | 752 | { |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
753 | aim_tlv_t *tlv; |
| 2086 | 754 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
755 | tlv = aim_tlv_gettlv(list, type, nth); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
756 | if (tlv == NULL) |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
757 | return NULL; |
| 2086 | 758 | |
|
13653
fab80366d565
[gaim-migrate @ 16053]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
759 | return aim_tlv_getvalue_as_string(tlv); |
| 2086 | 760 | } |
| 761 | ||
| 762 | /** | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
763 | * Retrieve the data from the nth TLV in the given TLV chain as an 8bit |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
764 | * integer. |
| 2086 | 765 | * |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
766 | * @param list Source TLV chain. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
767 | * @param type TLV type to search for. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
768 | * @param nth Index of TLV to return. |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
769 | * @return The value the TLV you were looking for, or 0 if one could |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
770 | * not be found. |
| 2086 | 771 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
772 | guint8 aim_tlv_get8(GSList *list, const guint16 type, const int nth) |
| 2086 | 773 | { |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
774 | aim_tlv_t *tlv; |
| 2086 | 775 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
776 | tlv = aim_tlv_gettlv(list, type, nth); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
777 | if (tlv == NULL) |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
778 | return 0; /* erm */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
779 | |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
780 | return aimutil_get8(tlv->value); |
| 2086 | 781 | } |
| 782 | ||
| 783 | /** | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
784 | * Retrieve the data from the nth TLV in the given TLV chain as a 16bit |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
785 | * integer. |
| 2086 | 786 | * |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
787 | * @param list Source TLV chain. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
788 | * @param type TLV type to search for. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
789 | * @param nth Index of TLV to return. |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
790 | * @return The value the TLV you were looking for, or 0 if one could |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
791 | * not be found. |
| 2086 | 792 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
793 | guint16 aim_tlv_get16(GSList *list, const guint16 type, const int nth) |
| 2086 | 794 | { |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
795 | aim_tlv_t *tlv; |
| 2086 | 796 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
797 | tlv = aim_tlv_gettlv(list, type, nth); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
798 | if (tlv == NULL) |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
799 | return 0; /* erm */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
800 | |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
801 | return aimutil_get16(tlv->value); |
| 2086 | 802 | } |
| 803 | ||
| 804 | /** | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
805 | * Retrieve the data from the nth TLV in the given TLV chain as a 32bit |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
806 | * integer. |
| 2086 | 807 | * |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
808 | * @param list Source TLV chain. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
809 | * @param type TLV type to search for. |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
810 | * @param nth Index of TLV to return. |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
811 | * @return The value the TLV you were looking for, or 0 if one could |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7166
diff
changeset
|
812 | * not be found. |
| 2086 | 813 | */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
814 | guint32 aim_tlv_get32(GSList *list, const guint16 type, const int nth) |
| 2086 | 815 | { |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
816 | aim_tlv_t *tlv; |
| 2086 | 817 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
818 | tlv = aim_tlv_gettlv(list, type, nth); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
819 | if (tlv == NULL) |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
820 | return 0; /* erm */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
821 | |
|
2246
8ade8b7421af
[gaim-migrate @ 2256]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
822 | return aimutil_get32(tlv->value); |
| 2086 | 823 | } |