annotate src/protocols/oscar/tlv.c @ 12949:9a5b9680aaeb

[gaim-migrate @ 15302] SF Patch #1406080 from Sadrul "Gaim leaks when you are away on AIM without any away message and autoreply is enabled for `When Away'. This patch fixes that. It also updates the timestamp for last-sent autoreply only when the autoreply was actually sent." It also removes some duplicated code. I tweaked a couple other things in the function to narrow variable scope a little more. It looked good and even compiled. What more can you ask for? committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Thu, 19 Jan 2006 07:36:38 +0000
parents bcd7bd6a42dd
children f2431a7e33aa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 #define FAIM_INTERNAL
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 #include <aim.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
5 static aim_tlv_t *createtlv(fu16_t type, fu16_t length, fu8_t *value)
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
6 {
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
7 aim_tlv_t *ret;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
8
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
9 if (!(ret = (aim_tlv_t *)malloc(sizeof(aim_tlv_t))))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
10 return NULL;
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
11 ret->type = type;
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
12 ret->length = length;
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
13 ret->value = value;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
14
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
15 return ret;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
16 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
17
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
18 static void freetlv(aim_tlv_t **oldtlv)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
19 {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
20
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
21 if (!oldtlv || !*oldtlv)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
22 return;
10986
ecc0f22db510 [gaim-migrate @ 12822]
Mark Doliner <mark@kingant.net>
parents: 9933
diff changeset
23
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
24 free((*oldtlv)->value);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
25 free(*oldtlv);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
26 *oldtlv = NULL;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
27
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
28 return;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
29 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
30
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
32 * Read a TLV chain from a buffer.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 * Reads and parses a series of TLV patterns from a data buffer; the
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 * returned structure is manipulatable with the rest of the TLV
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
36 * routines. When done with a TLV chain, aim_tlvlist_free() should
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 * be called to free the dynamic substructures.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 *
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
39 * XXX There should be a flag setable here to have the tlvlist contain
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
40 * bstream references, so that at least the ->value portion of each
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
41 * element doesn't need to be malloc/memcpy'd. This could prove to be
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
42 * just as efficient as the in-place TLV parsing used in a couple places
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
43 * in libfaim.
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
44 *
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
45 * @param bs Input bstream
8790
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
46 * @return Return the TLV chain read
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
48 faim_internal aim_tlvlist_t *aim_tlvlist_read(aim_bstream_t *bs)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
50 aim_tlvlist_t *list = NULL, *cur;
10986
ecc0f22db510 [gaim-migrate @ 12822]
Mark Doliner <mark@kingant.net>
parents: 9933
diff changeset
51
3459
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
52 while (aim_bstream_empty(bs) > 0) {
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
53 fu16_t type, length;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
55 type = aimbs_get16(bs);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
56 length = aimbs_get16(bs);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
58 #if 0 /* temporarily disabled until I know if they're still doing it or not */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
59 /*
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
60 * Okay, so now AOL has decided that any TLV of
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
61 * type 0x0013 can only be two bytes, despite
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
62 * what the actual given length is. So here
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
63 * we dump any invalid TLVs of that sort. Hopefully
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
64 * there's no special cases to this special case.
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
65 * - mid (30jun2000)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
66 */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
67 if ((type == 0x0013) && (length != 0x0002))
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
68 length = 0x0002;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
69 #else
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
70 if (0)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
71 ;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
72 #endif
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
73 else {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74
3459
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
75 if (length > aim_bstream_empty(bs)) {
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
76 aim_tlvlist_free(&list);
3459
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
77 return NULL;
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
78 }
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
79
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
80 cur = (aim_tlvlist_t *)malloc(sizeof(aim_tlvlist_t));
3459
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
81 if (!cur) {
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
82 aim_tlvlist_free(&list);
3459
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
83 return NULL;
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
84 }
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
85
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
86 memset(cur, 0, sizeof(aim_tlvlist_t));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
88 cur->tlv = createtlv(type, length, NULL);
3459
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
89 if (!cur->tlv) {
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
90 free(cur);
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
91 aim_tlvlist_free(&list);
3459
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
92 return NULL;
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
93 }
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
94 if (cur->tlv->length > 0) {
11159
bd8ac1d4b2f2 [gaim-migrate @ 13246]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
95 cur->tlv->value = aimbs_getraw(bs, length);
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
96 if (!cur->tlv->value) {
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
97 freetlv(&cur->tlv);
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
98 free(cur);
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
99 aim_tlvlist_free(&list);
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
100 return NULL;
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
101 }
3459
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
102 }
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
103
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
104 cur->next = list;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
105 list = cur;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
106 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
109 return list;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
111
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
112 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
113 * Read a TLV chain from a buffer.
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
114 *
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
115 * Reads and parses a series of TLV patterns from a data buffer; the
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
116 * returned structure is manipulatable with the rest of the TLV
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
117 * routines. When done with a TLV chain, aim_tlvlist_free() should
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
118 * be called to free the dynamic substructures.
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
119 *
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
120 * XXX There should be a flag setable here to have the tlvlist contain
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
121 * bstream references, so that at least the ->value portion of each
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
122 * element doesn't need to be malloc/memcpy'd. This could prove to be
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
123 * just as efficient as the in-place TLV parsing used in a couple places
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
124 * in libfaim.
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
125 *
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
126 * @param bs Input bstream
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
127 * @param num The max number of TLVs that will be read, or -1 if unlimited.
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
128 * There are a number of places where you want to read in a tlvchain,
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
129 * but the chain is not at the end of the SNAC, and the chain is
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
130 * preceded by the number of TLVs. So you can limit that with this.
8790
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
131 * @return Return the TLV chain read
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
132 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
133 faim_internal aim_tlvlist_t *aim_tlvlist_readnum(aim_bstream_t *bs, fu16_t num)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
134 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
135 aim_tlvlist_t *list = NULL, *cur;
4317
7c9f3d0fe8b2 [gaim-migrate @ 4571]
Mark Doliner <mark@kingant.net>
parents: 4230
diff changeset
136
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
137 while ((aim_bstream_empty(bs) > 0) && (num != 0)) {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
138 fu16_t type, length;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
139
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
140 type = aimbs_get16(bs);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
141 length = aimbs_get16(bs);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
142
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
143 if (length > aim_bstream_empty(bs)) {
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
144 aim_tlvlist_free(&list);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
145 return NULL;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
146 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
147
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
148 cur = (aim_tlvlist_t *)malloc(sizeof(aim_tlvlist_t));
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
149 if (!cur) {
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
150 aim_tlvlist_free(&list);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
151 return NULL;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
152 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
153
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
154 memset(cur, 0, sizeof(aim_tlvlist_t));
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
155
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
156 cur->tlv = createtlv(type, length, NULL);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
157 if (!cur->tlv) {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
158 free(cur);
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
159 aim_tlvlist_free(&list);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
160 return NULL;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
161 }
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
162 if (cur->tlv->length > 0) {
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
163 cur->tlv->value = aimbs_getraw(bs, length);
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
164 if (!cur->tlv->value) {
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
165 freetlv(&cur->tlv);
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
166 free(cur);
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
167 aim_tlvlist_free(&list);
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
168 return NULL;
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
169 }
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
170 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
171
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
172 if (num > 0)
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
173 num--;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
174 cur->next = list;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
175 list = cur;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
176 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
177
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
178 return list;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
179 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
180
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3912
diff changeset
181 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
182 * Read a TLV chain from a buffer.
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
183 *
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
184 * Reads and parses a series of TLV patterns from a data buffer; the
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
185 * returned structure is manipulatable with the rest of the TLV
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
186 * routines. When done with a TLV chain, aim_tlvlist_free() should
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
187 * be called to free the dynamic substructures.
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
188 *
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
189 * XXX There should be a flag setable here to have the tlvlist contain
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
190 * bstream references, so that at least the ->value portion of each
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
191 * element doesn't need to be malloc/memcpy'd. This could prove to be
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
192 * just as efficient as the in-place TLV parsing used in a couple places
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
193 * in libfaim.
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
194 *
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
195 * @param bs Input bstream
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
196 * @param len The max length in bytes that will be read.
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
197 * There are a number of places where you want to read in a tlvchain,
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
198 * but the chain is not at the end of the SNAC, and the chain is
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
199 * preceded by the length of the TLVs. So you can limit that with this.
8790
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
200 * @return Return the TLV chain read
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
201 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
202 faim_internal aim_tlvlist_t *aim_tlvlist_readlen(aim_bstream_t *bs, fu16_t len)
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
203 {
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
204 aim_tlvlist_t *list = NULL, *cur;
4317
7c9f3d0fe8b2 [gaim-migrate @ 4571]
Mark Doliner <mark@kingant.net>
parents: 4230
diff changeset
205
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
206 while ((aim_bstream_empty(bs) > 0) && (len > 0)) {
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
207 fu16_t type, length;
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
208
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
209 type = aimbs_get16(bs);
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
210 length = aimbs_get16(bs);
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
211
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
212 if (length > aim_bstream_empty(bs)) {
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
213 aim_tlvlist_free(&list);
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
214 return NULL;
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
215 }
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
216
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
217 cur = (aim_tlvlist_t *)malloc(sizeof(aim_tlvlist_t));
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
218 if (!cur) {
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
219 aim_tlvlist_free(&list);
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
220 return NULL;
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
221 }
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
222
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
223 memset(cur, 0, sizeof(aim_tlvlist_t));
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
224
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
225 cur->tlv = createtlv(type, length, NULL);
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
226 if (!cur->tlv) {
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
227 free(cur);
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
228 aim_tlvlist_free(&list);
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
229 return NULL;
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
230 }
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
231 if (cur->tlv->length > 0) {
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
232 cur->tlv->value = aimbs_getraw(bs, length);
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
233 if (!cur->tlv->value) {
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
234 freetlv(&cur->tlv);
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
235 free(cur);
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
236 aim_tlvlist_free(&list);
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
237 return NULL;
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
238 }
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
239 }
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
240
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
241 len -= aim_tlvlist_size(&cur);
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
242 cur->next = list;
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
243 list = cur;
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
244 }
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
245
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
246 return list;
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
247 }
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
248
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
249 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
250 * Duplicate a TLV chain.
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
251 * This is pretty self explanatory.
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
252 *
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
253 * @param orig The TLV chain you want to make a copy of.
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
254 * @return A newly allocated TLV chain.
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
255 */
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
256 faim_internal aim_tlvlist_t *aim_tlvlist_copy(aim_tlvlist_t *orig)
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
257 {
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
258 aim_tlvlist_t *new = NULL;
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
259
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
260 while (orig) {
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
261 aim_tlvlist_add_raw(&new, orig->tlv->type, orig->tlv->length, orig->tlv->value);
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
262 orig = orig->next;
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
263 }
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
264
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
265 return new;
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
266 }
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
267
6101
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
268 /*
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
269 * Compare two TLV lists for equality. This probably is not the most
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
270 * efficient way to do this.
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
271 *
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
272 * @param one One of the TLV chains to compare.
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
273 * @param two The other TLV chain to compare.
8790
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
274 * @return Return 0 if the lists are the same, return 1 if they are different.
6101
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
275 */
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
276 faim_internal int aim_tlvlist_cmp(aim_tlvlist_t *one, aim_tlvlist_t *two)
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
277 {
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
278 aim_bstream_t bs1, bs2;
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
279
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
280 if (aim_tlvlist_size(&one) != aim_tlvlist_size(&two))
6101
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
281 return 1;
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
282
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
283 aim_bstream_init(&bs1, ((fu8_t *)malloc(aim_tlvlist_size(&one)*sizeof(fu8_t))), aim_tlvlist_size(&one));
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
284 aim_bstream_init(&bs2, ((fu8_t *)malloc(aim_tlvlist_size(&two)*sizeof(fu8_t))), aim_tlvlist_size(&two));
6101
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
285
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
286 aim_tlvlist_write(&bs1, &one);
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
287 aim_tlvlist_write(&bs2, &two);
6101
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
288
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
289 if (memcmp(bs1.data, bs2.data, bs1.len)) {
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
290 free(bs1.data);
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
291 free(bs2.data);
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
292 return 1;
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
293 }
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
294
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
295 free(bs1.data);
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
296 free(bs2.data);
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
297
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
298 return 0;
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
299 }
e4a5085fb870 [gaim-migrate @ 6560]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
300
4230
9f729d6d88a6 [gaim-migrate @ 4475]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
301 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
302 * Free a TLV chain structure
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
303 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
304 * Walks the list of TLVs in the passed TLV chain and
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
305 * frees each one. Note that any references to this data
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
306 * should be removed before calling this.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
307 *
8790
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
308 * @param list Chain to be freed
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
309 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
310 faim_internal void aim_tlvlist_free(aim_tlvlist_t **list)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
311 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
312 aim_tlvlist_t *cur;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
313
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
314 if (!list || !*list)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
315 return;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
316
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
317 for (cur = *list; cur; ) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
318 aim_tlvlist_t *tmp;
10986
ecc0f22db510 [gaim-migrate @ 12822]
Mark Doliner <mark@kingant.net>
parents: 9933
diff changeset
319
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
320 freetlv(&cur->tlv);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
321
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
322 tmp = cur->next;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
323 free(cur);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
324 cur = tmp;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
325 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
326
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
327 list = NULL;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
328
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
329 return;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
330 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
331
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
332 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
333 * Count the number of TLVs in a chain.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
334 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
335 * @param list Chain to be counted.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
336 * @return The number of TLVs stored in the passed chain.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
337 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
338 faim_internal int aim_tlvlist_count(aim_tlvlist_t **list)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
339 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
340 aim_tlvlist_t *cur;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
341 int count;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
342
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
343 if (!list || !*list)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
344 return 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
345
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
346 for (cur = *list, count = 0; cur; cur = cur->next)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
347 count++;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
348
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
349 return count;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
350 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
351
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
352 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
353 * Count the number of bytes in a TLV chain.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
354 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
355 * @param list Chain to be sized
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
356 * @return The number of bytes that would be needed to
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
357 * write the passed TLV chain to a data buffer.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
358 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
359 faim_internal int aim_tlvlist_size(aim_tlvlist_t **list)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
360 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
361 aim_tlvlist_t *cur;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
362 int size;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
363
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
364 if (!list || !*list)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
365 return 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
366
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
367 for (cur = *list, size = 0; cur; cur = cur->next)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
368 size += (4 + cur->tlv->length);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
369
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
370 return size;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
371 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
372
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
373 /**
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
374 * Adds the passed string as a TLV element of the passed type
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
375 * to the TLV chain.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
376 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
377 * @param list Desination chain (%NULL pointer if empty).
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
378 * @param type TLV type.
8790
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
379 * @param length Length of string to add (not including %NULL).
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
380 * @param value String to add.
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
381 * @return The size of the value added.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
382 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
383 faim_internal int aim_tlvlist_add_raw(aim_tlvlist_t **list, const fu16_t type, const fu16_t length, const fu8_t *value)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
384 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
385 aim_tlvlist_t *newtlv, *cur;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
386
7166
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
387 if (list == NULL)
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
388 return 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
389
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
390 if (!(newtlv = (aim_tlvlist_t *)malloc(sizeof(aim_tlvlist_t))))
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
391 return 0;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
392 memset(newtlv, 0x00, sizeof(aim_tlvlist_t));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
393
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
394 if (!(newtlv->tlv = createtlv(type, length, NULL))) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
395 free(newtlv);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
396 return 0;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
397 }
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
398 if (newtlv->tlv->length > 0) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
399 newtlv->tlv->value = (fu8_t *)malloc(newtlv->tlv->length);
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
400 memcpy(newtlv->tlv->value, value, newtlv->tlv->length);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
401 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
402
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
403 if (!*list)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
404 *list = newtlv;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
405 else {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
406 for(cur = *list; cur->next; cur = cur->next)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
407 ;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
408 cur->next = newtlv;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
409 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
410
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
411 return newtlv->tlv->length;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
412 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
413
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
414 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
415 * Add a one byte integer to a TLV chain.
2821
9467e4ee81be [gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2421
diff changeset
416 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
417 * @param list Destination chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
418 * @param type TLV type to add.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
419 * @param value Value to add.
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
420 * @return The size of the value added.
2821
9467e4ee81be [gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2421
diff changeset
421 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
422 faim_internal int aim_tlvlist_add_8(aim_tlvlist_t **list, const fu16_t type, const fu8_t value)
2821
9467e4ee81be [gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2421
diff changeset
423 {
9467e4ee81be [gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2421
diff changeset
424 fu8_t v8[1];
9467e4ee81be [gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2421
diff changeset
425
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
426 aimutil_put8(v8, value);
2821
9467e4ee81be [gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2421
diff changeset
427
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
428 return aim_tlvlist_add_raw(list, type, 1, v8);
2821
9467e4ee81be [gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2421
diff changeset
429 }
9467e4ee81be [gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2421
diff changeset
430
9467e4ee81be [gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2421
diff changeset
431 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
432 * Add a two byte integer to a TLV chain.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
433 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
434 * @param list Destination chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
435 * @param type TLV type to add.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
436 * @param value Value to add.
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
437 * @return The size of the value added.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
438 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
439 faim_internal int aim_tlvlist_add_16(aim_tlvlist_t **list, const fu16_t type, const fu16_t value)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
440 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
441 fu8_t v16[2];
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
442
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
443 aimutil_put16(v16, value);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
444
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
445 return aim_tlvlist_add_raw(list, type, 2, v16);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
446 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
447
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
448 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
449 * Add a four byte integer to a TLV chain.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
450 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
451 * @param list Destination chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
452 * @param type TLV type to add.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
453 * @param value Value to add.
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
454 * @return The size of the value added.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
455 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
456 faim_internal int aim_tlvlist_add_32(aim_tlvlist_t **list, const fu16_t type, const fu32_t value)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
457 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
458 fu8_t v32[4];
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
459
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
460 aimutil_put32(v32, value);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
461
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
462 return aim_tlvlist_add_raw(list, type, 4, v32);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
463 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
464
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
465 /**
10986
ecc0f22db510 [gaim-migrate @ 12822]
Mark Doliner <mark@kingant.net>
parents: 9933
diff changeset
466 * Add a string to a TLV chain.
ecc0f22db510 [gaim-migrate @ 12822]
Mark Doliner <mark@kingant.net>
parents: 9933
diff changeset
467 *
ecc0f22db510 [gaim-migrate @ 12822]
Mark Doliner <mark@kingant.net>
parents: 9933
diff changeset
468 * @param list Destination chain.
ecc0f22db510 [gaim-migrate @ 12822]
Mark Doliner <mark@kingant.net>
parents: 9933
diff changeset
469 * @param type TLV type to add.
ecc0f22db510 [gaim-migrate @ 12822]
Mark Doliner <mark@kingant.net>
parents: 9933
diff changeset
470 * @param value Value to add.
ecc0f22db510 [gaim-migrate @ 12822]
Mark Doliner <mark@kingant.net>
parents: 9933
diff changeset
471 * @return The size of the value added.
ecc0f22db510 [gaim-migrate @ 12822]
Mark Doliner <mark@kingant.net>
parents: 9933
diff changeset
472 */
10991
1798ad0be460 [gaim-migrate @ 12829]
Mark Doliner <mark@kingant.net>
parents: 10990
diff changeset
473 faim_internal int aim_tlvlist_add_str(aim_tlvlist_t **list, const fu16_t type, const char *value)
10986
ecc0f22db510 [gaim-migrate @ 12822]
Mark Doliner <mark@kingant.net>
parents: 9933
diff changeset
474 {
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10986
diff changeset
475 return aim_tlvlist_add_raw(list, type, strlen(value), (fu8_t *)value);
10986
ecc0f22db510 [gaim-migrate @ 12822]
Mark Doliner <mark@kingant.net>
parents: 9933
diff changeset
476 }
ecc0f22db510 [gaim-migrate @ 12822]
Mark Doliner <mark@kingant.net>
parents: 9933
diff changeset
477
ecc0f22db510 [gaim-migrate @ 12822]
Mark Doliner <mark@kingant.net>
parents: 9933
diff changeset
478 /**
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
479 * Adds a block of capability blocks to a TLV chain. The bitfield
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
480 * passed in should be a bitwise %OR of any of the %AIM_CAPS constants:
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
481 *
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
482 * %AIM_CAPS_BUDDYICON Supports Buddy Icons
8092
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 7167
diff changeset
483 * %AIM_CAPS_TALK Supports Voice Chat
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
484 * %AIM_CAPS_IMIMAGE Supports DirectIM/IMImage
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
485 * %AIM_CAPS_CHAT Supports Chat
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
486 * %AIM_CAPS_GETFILE Supports Get File functions
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
487 * %AIM_CAPS_SENDFILE Supports Send File functions
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
488 *
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
489 * @param list Destination chain
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
490 * @param type TLV type to add
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
491 * @param caps Bitfield of capability flags to send
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
492 * @return The size of the value added.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
493 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
494 faim_internal int aim_tlvlist_add_caps(aim_tlvlist_t **list, const fu16_t type, const fu32_t caps)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
495 {
2866
6d62d4520460 [gaim-migrate @ 2879]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2821
diff changeset
496 fu8_t buf[16*16]; /* XXX icky fixed length buffer */
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
497 aim_bstream_t bs;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
498
2421
95b4ec08abec [gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2270
diff changeset
499 if (!caps)
95b4ec08abec [gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2270
diff changeset
500 return 0; /* nothing there anyway */
95b4ec08abec [gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2270
diff changeset
501
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
502 aim_bstream_init(&bs, buf, sizeof(buf));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
503
11285
bcd7bd6a42dd [gaim-migrate @ 13482]
Mark Doliner <mark@kingant.net>
parents: 11159
diff changeset
504 aimbs_putcaps(&bs, caps);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
505
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
506 return aim_tlvlist_add_raw(list, type, aim_bstream_curpos(&bs), buf);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
507 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
508
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
509 /**
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
510 * Adds the given userinfo struct to a TLV chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
511 *
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
512 * @param list Destination chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
513 * @param type TLV type to add.
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
514 * @return The size of the value added.
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
515 */
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
516 faim_internal int aim_tlvlist_add_userinfo(aim_tlvlist_t **list, fu16_t type, aim_userinfo_t *userinfo)
2270
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
517 {
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
518 fu8_t buf[1024]; /* bleh */
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
519 aim_bstream_t bs;
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
520
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
521 aim_bstream_init(&bs, buf, sizeof(buf));
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
522
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
523 aim_putuserinfo(&bs, userinfo);
2270
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
524
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
525 return aim_tlvlist_add_raw(list, type, aim_bstream_curpos(&bs), buf);
2270
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
526 }
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
527
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
528 /**
8225
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
529 * Adds the given chatroom info to a TLV chain.
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
530 *
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
531 * @param list Destination chain.
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
532 * @param type TLV type to add.
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
533 * @param roomname The name of the chat.
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
534 * @param instance The instance.
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
535 * @return The size of the value added.
8225
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
536 */
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
537 faim_internal int aim_tlvlist_add_chatroom(aim_tlvlist_t **list, fu16_t type, fu16_t exchange, const char *roomname, fu16_t instance)
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
538 {
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
539 fu8_t *buf;
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
540 int len;
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
541 aim_bstream_t bs;
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
542
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
543 len = 2 + 1 + strlen(roomname) + 2;
10986
ecc0f22db510 [gaim-migrate @ 12822]
Mark Doliner <mark@kingant.net>
parents: 9933
diff changeset
544
8225
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
545 if (!(buf = malloc(len)))
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
546 return 0;
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
547
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
548 aim_bstream_init(&bs, buf, len);
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
549
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
550 aimbs_put16(&bs, exchange);
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
551 aimbs_put8(&bs, strlen(roomname));
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10986
diff changeset
552 aimbs_putstr(&bs, roomname);
8225
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
553 aimbs_put16(&bs, instance);
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
554
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
555 len = aim_tlvlist_add_raw(list, type, aim_bstream_curpos(&bs), buf);
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
556
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
557 free(buf);
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
558
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
559 return len;
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
560 }
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
561
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
562 /**
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
563 * Adds a TLV with a zero length to a TLV chain.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
564 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
565 * @param list Destination chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
566 * @param type TLV type to add.
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
567 * @return The size of the value added.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
568 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
569 faim_internal int aim_tlvlist_add_noval(aim_tlvlist_t **list, const fu16_t type)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
570 {
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
571 return aim_tlvlist_add_raw(list, type, 0, NULL);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
572 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
573
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
574 /*
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
575 * Note that the inner TLV chain will not be modifiable as a tlvchain once
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
576 * it is written using this. Or rather, it can be, but updates won't be
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
577 * made to this.
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
578 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
579 * XXX should probably support sublists for real.
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
580 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
581 * This is so neat.
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
582 *
8790
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
583 * @param list Destination chain.
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
584 * @param type TLV type to add.
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
585 * @param t1 The TLV chain you want to write.
8794
4048e93b8ece [gaim-migrate @ 9556]
Mark Doliner <mark@kingant.net>
parents: 8790
diff changeset
586 * @return The number of bytes written to the destination TLV chain.
4048e93b8ece [gaim-migrate @ 9556]
Mark Doliner <mark@kingant.net>
parents: 8790
diff changeset
587 * 0 is returned if there was an error or if the destination
4048e93b8ece [gaim-migrate @ 9556]
Mark Doliner <mark@kingant.net>
parents: 8790
diff changeset
588 * TLV chain has length 0.
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
589 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
590 faim_internal int aim_tlvlist_add_frozentlvlist(aim_tlvlist_t **list, fu16_t type, aim_tlvlist_t **tl)
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
591 {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
592 fu8_t *buf;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
593 int buflen;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
594 aim_bstream_t bs;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
595
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
596 buflen = aim_tlvlist_size(tl);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
597
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
598 if (buflen <= 0)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
599 return 0;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
600
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
601 if (!(buf = malloc(buflen)))
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
602 return 0;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
603
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
604 aim_bstream_init(&bs, buf, buflen);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
605
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
606 aim_tlvlist_write(&bs, tl);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
607
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
608 aim_tlvlist_add_raw(list, type, aim_bstream_curpos(&bs), buf);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
609
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
610 free(buf);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
611
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
612 return buflen;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
613 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
614
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
615 /**
7166
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
616 * Substitute a TLV of a given type with a new TLV of the same type. If
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
617 * you attempt to replace a TLV that does not exist, this function will
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
618 * just add a new TLV as if you called aim_tlvlist_add_raw().
7166
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
619 *
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
620 * @param list Desination chain (%NULL pointer if empty).
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
621 * @param type TLV type.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
622 * @param length Length of string to add (not including %NULL).
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
623 * @param value String to add.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
624 * @return The length of the TLV.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
625 */
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
626 faim_internal int aim_tlvlist_replace_raw(aim_tlvlist_t **list, const fu16_t type, const fu16_t length, const fu8_t *value)
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
627 {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
628 aim_tlvlist_t *cur;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
629
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
630 if (list == NULL)
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
631 return 0;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
632
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
633 for (cur = *list; ((cur != NULL) && (cur->tlv->type != type)); cur = cur->next);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
634 if (cur == NULL)
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
635 return aim_tlvlist_add_raw(list, type, length, value);
7166
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
636
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
637 free(cur->tlv->value);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
638 cur->tlv->length = length;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
639 if (cur->tlv->length > 0) {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
640 cur->tlv->value = (fu8_t *)malloc(cur->tlv->length);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
641 memcpy(cur->tlv->value, value, cur->tlv->length);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
642 } else
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
643 cur->tlv->value = NULL;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
644
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
645 return cur->tlv->length;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
646 }
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
647
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
648 /**
11159
bd8ac1d4b2f2 [gaim-migrate @ 13246]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
649 * Substitute a TLV of a given type with a new TLV of the same type. If
bd8ac1d4b2f2 [gaim-migrate @ 13246]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
650 * you attempt to replace a TLV that does not exist, this function will
10993
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10991
diff changeset
651 * just add a new TLV as if you called aim_tlvlist_add_str().
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10991
diff changeset
652 *
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10991
diff changeset
653 * @param list Desination chain (%NULL pointer if empty).
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10991
diff changeset
654 * @param type TLV type.
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10991
diff changeset
655 * @param str String to add.
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10991
diff changeset
656 * @return The length of the TLV.
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10991
diff changeset
657 */
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10991
diff changeset
658 faim_internal int aim_tlvlist_replace_str(aim_tlvlist_t **list, const fu16_t type, const char *str)
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10991
diff changeset
659 {
11159
bd8ac1d4b2f2 [gaim-migrate @ 13246]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
660 return aim_tlvlist_replace_raw(list, type, strlen(str), (const guchar *)str);
10993
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10991
diff changeset
661 }
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10991
diff changeset
662
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10991
diff changeset
663 /**
11159
bd8ac1d4b2f2 [gaim-migrate @ 13246]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
664 * Substitute a TLV of a given type with a new TLV of the same type. If
bd8ac1d4b2f2 [gaim-migrate @ 13246]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
665 * you attempt to replace a TLV that does not exist, this function will
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
666 * just add a new TLV as if you called aim_tlvlist_add_raw().
7166
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
667 *
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
668 * @param list Desination chain (%NULL pointer if empty).
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
669 * @param type TLV type.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
670 * @return The length of the TLV.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
671 */
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
672 faim_internal int aim_tlvlist_replace_noval(aim_tlvlist_t **list, const fu16_t type)
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
673 {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
674 return aim_tlvlist_replace_raw(list, type, 0, NULL);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
675 }
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
676
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
677 /**
11159
bd8ac1d4b2f2 [gaim-migrate @ 13246]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
678 * Substitute a TLV of a given type with a new TLV of the same type. If
bd8ac1d4b2f2 [gaim-migrate @ 13246]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
679 * you attempt to replace a TLV that does not exist, this function will
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
680 * just add a new TLV as if you called aim_tlvlist_add_raw().
7166
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
681 *
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
682 * @param list Desination chain (%NULL pointer if empty).
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
683 * @param type TLV type.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
684 * @param value 8 bit value to add.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
685 * @return The length of the TLV.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
686 */
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
687 faim_internal int aim_tlvlist_replace_8(aim_tlvlist_t **list, const fu16_t type, const fu8_t value)
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
688 {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
689 fu8_t v8[1];
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
690
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
691 aimutil_put8(v8, value);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
692
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
693 return aim_tlvlist_replace_raw(list, type, 1, v8);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
694 }
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
695
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
696 /**
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
697 * Substitute a TLV of a given type with a new TLV of the same type. If
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
698 * you attempt to replace a TLV that does not exist, this function will
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
699 * just add a new TLV as if you called aim_tlvlist_add_raw().
7166
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
700 *
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
701 * @param list Desination chain (%NULL pointer if empty).
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
702 * @param type TLV type.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
703 * @param value 32 bit value to add.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
704 * @return The length of the TLV.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
705 */
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
706 faim_internal int aim_tlvlist_replace_32(aim_tlvlist_t **list, const fu16_t type, const fu32_t value)
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
707 {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
708 fu8_t v32[4];
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
709
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
710 aimutil_put32(v32, value);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
711
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
712 return aim_tlvlist_replace_raw(list, type, 4, v32);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
713 }
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
714
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
715 /**
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
716 * Remove a TLV of a given type. If you attempt to remove a TLV that
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
717 * does not exist, nothing happens.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
718 *
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
719 * @param list Desination chain (%NULL pointer if empty).
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
720 * @param type TLV type.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
721 */
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
722 faim_internal void aim_tlvlist_remove(aim_tlvlist_t **list, const fu16_t type)
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
723 {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
724 aim_tlvlist_t *del;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
725
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
726 if (!list || !(*list))
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
727 return;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
728
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
729 /* Remove the item from the list */
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
730 if ((*list)->tlv->type == type) {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
731 del = *list;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
732 *list = (*list)->next;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
733 } else {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
734 aim_tlvlist_t *cur;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
735 for (cur=*list; (cur->next && (cur->next->tlv->type!=type)); cur=cur->next);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
736 if (!cur->next)
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
737 return;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
738 del = cur->next;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
739 cur->next = del->next;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
740 }
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
741
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
742 /* Free the removed item */
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
743 free(del->tlv->value);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
744 free(del->tlv);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
745 free(del);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
746 }
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
747
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
748 /**
8794
4048e93b8ece [gaim-migrate @ 9556]
Mark Doliner <mark@kingant.net>
parents: 8790
diff changeset
749 * Write a TLV chain into a data buffer.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
750 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
751 * Copies a TLV chain into a raw data buffer, writing only the number
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
752 * of bytes specified. This operation does not free the chain;
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
753 * aim_tlvlist_free() must still be called to free up the memory used
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
754 * by the chain structures.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
755 *
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
756 * XXX clean this up, make better use of bstreams
8790
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
757 *
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
758 * @param bs Input bstream
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
759 * @param list Source TLV chain
8794
4048e93b8ece [gaim-migrate @ 9556]
Mark Doliner <mark@kingant.net>
parents: 8790
diff changeset
760 * @return Return 0 if the destination bstream is too small.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
761 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
762 faim_internal int aim_tlvlist_write(aim_bstream_t *bs, aim_tlvlist_t **list)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
763 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
764 int goodbuflen;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
765 aim_tlvlist_t *cur;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
766
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
767 /* do an initial run to test total length */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
768 goodbuflen = aim_tlvlist_size(list);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
769
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
770 if (goodbuflen > aim_bstream_empty(bs))
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
771 return 0; /* not enough buffer */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
772
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
773 /* do the real write-out */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
774 for (cur = *list; cur; cur = cur->next) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
775 aimbs_put16(bs, cur->tlv->type);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
776 aimbs_put16(bs, cur->tlv->length);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
777 if (cur->tlv->length)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
778 aimbs_putraw(bs, cur->tlv->value, cur->tlv->length);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
779 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
780
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
781 return 1; /* XXX this is a nonsensical return */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
782 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
783
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
784
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
785 /**
7166
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
786 * Grab the Nth TLV of type type in the TLV list list.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
787 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
788 * Returns a pointer to an aim_tlv_t of the specified type;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
789 * %NULL on error. The @nth parameter is specified starting at %1.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
790 * In most cases, there will be no more than one TLV of any type
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
791 * in a chain.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
792 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
793 * @param list Source chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
794 * @param type Requested TLV type.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
795 * @param nth Index of TLV of type to get.
7166
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
796 * @return The TLV you were looking for, or NULL if one could not be found.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
797 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
798 faim_internal aim_tlv_t *aim_tlv_gettlv(aim_tlvlist_t *list, const fu16_t type, const int nth)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
799 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
800 aim_tlvlist_t *cur;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
801 int i;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
802
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
803 for (cur = list, i = 0; cur; cur = cur->next) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
804 if (cur && cur->tlv) {
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
805 if (cur->tlv->type == type)
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
806 i++;
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
807 if (i >= nth)
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
808 return cur->tlv;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
809 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
810 }
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
811
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
812 return NULL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
813 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
814
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
815 /**
9933
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
816 * Get the length of the data of the nth TLV in the given TLV chain.
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
817 *
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
818 * @param list Source chain.
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
819 * @param type Requested TLV type.
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
820 * @param nth Index of TLV of type to get.
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
821 * @return The length of the data in this TLV, or -1 if the TLV could not be
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
822 * found. Unless -1 is returned, this value will be 2 bytes.
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
823 */
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
824 faim_internal int aim_tlv_getlength(aim_tlvlist_t *list, const fu16_t type, const int nth)
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
825 {
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
826 aim_tlvlist_t *cur;
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
827 int i;
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
828
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
829 for (cur = list, i = 0; cur; cur = cur->next) {
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
830 if (cur && cur->tlv) {
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
831 if (cur->tlv->type == type)
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
832 i++;
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
833 if (i >= nth)
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
834 return cur->tlv->length;
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
835 }
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
836 }
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
837
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
838 return -1;
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
839 }
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
840
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
841 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
842 * Retrieve the data from the nth TLV in the given TLV chain as a string.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
843 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
844 * @param list Source TLV chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
845 * @param type TLV type to search for.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
846 * @param nth Index of TLV to return.
11159
bd8ac1d4b2f2 [gaim-migrate @ 13246]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
847 * @return The value of the TLV you were looking for, or NULL if one could
bd8ac1d4b2f2 [gaim-migrate @ 13246]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
848 * not be found. This is a dynamic buffer and must be freed by the
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
849 * caller.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
850 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
851 faim_internal char *aim_tlv_getstr(aim_tlvlist_t *list, const fu16_t type, const int nth)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
852 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
853 aim_tlv_t *tlv;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
854 char *newstr;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
855
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
856 if (!(tlv = aim_tlv_gettlv(list, type, nth)))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
857 return NULL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
858
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
859 newstr = (char *) malloc(tlv->length + 1);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
860 memcpy(newstr, tlv->value, tlv->length);
7011
4375bf2d9020 [gaim-migrate @ 7574]
Mark Doliner <mark@kingant.net>
parents: 6101
diff changeset
861 newstr[tlv->length] = '\0';
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
862
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
863 return newstr;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
864 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
865
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
866 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
867 * Retrieve the data from the nth TLV in the given TLV chain as an 8bit
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
868 * integer.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
869 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
870 * @param list Source TLV chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
871 * @param type TLV type to search for.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
872 * @param nth Index of TLV to return.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
873 * @return The value the TLV you were looking for, or 0 if one could
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
874 * not be found.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
875 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
876 faim_internal fu8_t aim_tlv_get8(aim_tlvlist_t *list, const fu16_t type, const int nth)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
877 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
878 aim_tlv_t *tlv;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
879
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
880 if (!(tlv = aim_tlv_gettlv(list, type, nth)))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
881 return 0; /* erm */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
882 return aimutil_get8(tlv->value);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
883 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
884
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
885 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
886 * Retrieve the data from the nth TLV in the given TLV chain as a 16bit
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
887 * integer.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
888 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
889 * @param list Source TLV chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
890 * @param type TLV type to search for.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
891 * @param nth Index of TLV to return.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
892 * @return The value the TLV you were looking for, or 0 if one could
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
893 * not be found.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
894 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
895 faim_internal fu16_t aim_tlv_get16(aim_tlvlist_t *list, const fu16_t type, const int nth)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
896 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
897 aim_tlv_t *tlv;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
898
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
899 if (!(tlv = aim_tlv_gettlv(list, type, nth)))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
900 return 0; /* erm */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
901 return aimutil_get16(tlv->value);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
902 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
903
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
904 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
905 * Retrieve the data from the nth TLV in the given TLV chain as a 32bit
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
906 * integer.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
907 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
908 * @param list Source TLV chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
909 * @param type TLV type to search for.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
910 * @param nth Index of TLV to return.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
911 * @return The value the TLV you were looking for, or 0 if one could
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
912 * not be found.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
913 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
914 faim_internal fu32_t aim_tlv_get32(aim_tlvlist_t *list, const fu16_t type, const int nth)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
915 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
916 aim_tlv_t *tlv;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
917
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
918 if (!(tlv = aim_tlv_gettlv(list, type, nth)))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
919 return 0; /* erm */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
920 return aimutil_get32(tlv->value);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
921 }