annotate src/protocols/oscar/tlv.c @ 10463:9bed28273ec7

[gaim-migrate @ 11737] Felipe Contreras fixed the MSN HTTP Method. Yay! Thanks Felipe. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Fri, 31 Dec 2004 16:34:22 +0000
parents cee849d17167
children ecc0f22db510
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;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
23
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;
3459
d82f53194f09 [gaim-migrate @ 3507]
Sean Egan <seanegan@gmail.com>
parents: 2866
diff changeset
51
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) {
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
95 cur->tlv->value = aimbs_getraw(bs, length);
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;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
319
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 /**
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
466 * Adds a block of capability blocks to a TLV chain. The bitfield
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
467 * 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
468 *
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
469 * %AIM_CAPS_BUDDYICON Supports Buddy Icons
8092
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 7167
diff changeset
470 * %AIM_CAPS_TALK Supports Voice Chat
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
471 * %AIM_CAPS_IMIMAGE Supports DirectIM/IMImage
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
472 * %AIM_CAPS_CHAT Supports Chat
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
473 * %AIM_CAPS_GETFILE Supports Get File functions
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
474 * %AIM_CAPS_SENDFILE Supports Send File functions
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
475 *
7158
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
476 * @param list Destination chain
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
477 * @param type TLV type to add
aee5fd893aba [gaim-migrate @ 7725]
Mark Doliner <mark@kingant.net>
parents: 7011
diff changeset
478 * @param caps Bitfield of capability flags to send
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
479 * @return The size of the value added.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
480 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
481 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
482 {
2866
6d62d4520460 [gaim-migrate @ 2879]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2821
diff changeset
483 fu8_t buf[16*16]; /* XXX icky fixed length buffer */
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
484 aim_bstream_t bs;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
485
2421
95b4ec08abec [gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2270
diff changeset
486 if (!caps)
95b4ec08abec [gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2270
diff changeset
487 return 0; /* nothing there anyway */
95b4ec08abec [gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2270
diff changeset
488
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
489 aim_bstream_init(&bs, buf, sizeof(buf));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
490
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
491 aim_putcap(&bs, caps);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
492
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
493 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
494 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
495
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
496 /**
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
497 * Adds the given userinfo struct to a TLV chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
498 *
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
499 * @param list Destination chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
500 * @param type TLV type to add.
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
501 * @return The size of the value added.
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
502 */
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
503 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
504 {
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
505 fu8_t buf[1024]; /* bleh */
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
506 aim_bstream_t bs;
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
507
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
508 aim_bstream_init(&bs, buf, sizeof(buf));
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
509
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
510 aim_putuserinfo(&bs, userinfo);
2270
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
511
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
512 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
513 }
d82efea341ef [gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2246
diff changeset
514
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
515 /**
8225
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
516 * Adds the given chatroom info to a TLV chain.
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
517 *
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
518 * @param list Destination chain.
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
519 * @param type TLV type to add.
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
520 * @param roomname The name of the chat.
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
521 * @param instance The instance.
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
522 * @return The size of the value added.
8225
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
523 */
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
524 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
525 {
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
526 fu8_t *buf;
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
527 int len;
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
528 aim_bstream_t bs;
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
529
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
530 len = 2 + 1 + strlen(roomname) + 2;
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
531
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
532 if (!(buf = malloc(len)))
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
533 return 0;
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
534
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
535 aim_bstream_init(&bs, buf, len);
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 aimbs_put16(&bs, exchange);
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
538 aimbs_put8(&bs, strlen(roomname));
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
539 aimbs_putraw(&bs, roomname, strlen(roomname));
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
540 aimbs_put16(&bs, instance);
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
541
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
542 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
543
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
544 free(buf);
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
545
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
546 return len;
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
9790cda80d52 [gaim-migrate @ 8948]
Mark Doliner <mark@kingant.net>
parents: 8092
diff changeset
549 /**
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
550 * Adds a TLV with a zero length to a TLV chain.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
551 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
552 * @param list Destination chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
553 * @param type TLV type to add.
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8225
diff changeset
554 * @return The size of the value added.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
555 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
556 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
557 {
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
558 return aim_tlvlist_add_raw(list, type, 0, NULL);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
559 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
560
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
561 /*
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
562 * 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
563 * 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
564 * made to this.
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
565 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
566 * XXX should probably support sublists for real.
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
567 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
568 * This is so neat.
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
569 *
8790
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
570 * @param list Destination chain.
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
571 * @param type TLV type to add.
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
572 * @param t1 The TLV chain you want to write.
8794
4048e93b8ece [gaim-migrate @ 9556]
Mark Doliner <mark@kingant.net>
parents: 8790
diff changeset
573 * @return The number of bytes written to the destination TLV chain.
4048e93b8ece [gaim-migrate @ 9556]
Mark Doliner <mark@kingant.net>
parents: 8790
diff changeset
574 * 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
575 * TLV chain has length 0.
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
576 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
577 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
578 {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
579 fu8_t *buf;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
580 int buflen;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
581 aim_bstream_t bs;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
582
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
583 buflen = aim_tlvlist_size(tl);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
584
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
585 if (buflen <= 0)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
586 return 0;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
587
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
588 if (!(buf = malloc(buflen)))
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
589 return 0;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
590
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
591 aim_bstream_init(&bs, buf, buflen);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
592
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
593 aim_tlvlist_write(&bs, tl);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
594
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
595 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
596
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
597 free(buf);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
598
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
599 return buflen;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
600 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
601
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
602 /**
7166
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
603 * 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
604 * 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
605 * 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
606 *
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
607 * @param list Desination chain (%NULL pointer if empty).
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
608 * @param type TLV type.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
609 * @param length Length of string to add (not including %NULL).
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
610 * @param value String to add.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
611 * @return The length of the TLV.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
612 */
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
613 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
614 {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
615 aim_tlvlist_t *cur;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
616
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
617 if (list == NULL)
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
618 return 0;
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 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
621 if (cur == NULL)
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
622 return aim_tlvlist_add_raw(list, type, length, value);
7166
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
623
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
624 free(cur->tlv->value);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
625 cur->tlv->length = length;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
626 if (cur->tlv->length > 0) {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
627 cur->tlv->value = (fu8_t *)malloc(cur->tlv->length);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
628 memcpy(cur->tlv->value, value, cur->tlv->length);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
629 } else
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
630 cur->tlv->value = NULL;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
631
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
632 return cur->tlv->length;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
633 }
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
634
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
635 /**
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
636 * 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
637 * 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
638 * 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
639 *
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
640 * @param list Desination chain (%NULL pointer if empty).
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
641 * @param type TLV type.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
642 * @return The length of the TLV.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
643 */
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
644 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
645 {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
646 return aim_tlvlist_replace_raw(list, type, 0, NULL);
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
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
649 /**
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
650 * 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
651 * 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
652 * 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
653 *
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
654 * @param list Desination chain (%NULL pointer if empty).
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
655 * @param type TLV type.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
656 * @param value 8 bit value to add.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
657 * @return The length of the TLV.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
658 */
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
659 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
660 {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
661 fu8_t v8[1];
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
662
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
663 aimutil_put8(v8, value);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
664
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
665 return aim_tlvlist_replace_raw(list, type, 1, v8);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
666 }
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 /**
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
669 * 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
670 * 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
671 * 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
672 *
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
673 * @param list Desination chain (%NULL pointer if empty).
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
674 * @param type TLV type.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
675 * @param value 32 bit value to add.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
676 * @return The length of the TLV.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
677 */
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
678 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
679 {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
680 fu8_t v32[4];
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 aimutil_put32(v32, value);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
683
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
684 return aim_tlvlist_replace_raw(list, type, 4, v32);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
685 }
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 /**
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
688 * 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
689 * does not exist, nothing happens.
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 * @param list Desination chain (%NULL pointer if empty).
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
692 * @param type TLV type.
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
693 */
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
694 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
695 {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
696 aim_tlvlist_t *del;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
697
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
698 if (!list || !(*list))
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
699 return;
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 /* Remove the item from the list */
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
702 if ((*list)->tlv->type == type) {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
703 del = *list;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
704 *list = (*list)->next;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
705 } else {
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
706 aim_tlvlist_t *cur;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
707 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
708 if (!cur->next)
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
709 return;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
710 del = cur->next;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
711 cur->next = del->next;
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
712 }
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 /* Free the removed item */
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
715 free(del->tlv->value);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
716 free(del->tlv);
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
717 free(del);
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
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
720 /**
8794
4048e93b8ece [gaim-migrate @ 9556]
Mark Doliner <mark@kingant.net>
parents: 8790
diff changeset
721 * Write a TLV chain into a data buffer.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
722 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
723 * 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
724 * of bytes specified. This operation does not free the chain;
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
725 * 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
726 * by the chain structures.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
727 *
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
728 * XXX clean this up, make better use of bstreams
8790
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
729 *
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
730 * @param bs Input bstream
240c6282f546 [gaim-migrate @ 9552]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
731 * @param list Source TLV chain
8794
4048e93b8ece [gaim-migrate @ 9556]
Mark Doliner <mark@kingant.net>
parents: 8790
diff changeset
732 * @return Return 0 if the destination bstream is too small.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
733 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
734 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
735 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
736 int goodbuflen;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
737 aim_tlvlist_t *cur;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
738
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
739 /* do an initial run to test total length */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
740 goodbuflen = aim_tlvlist_size(list);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
741
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
742 if (goodbuflen > aim_bstream_empty(bs))
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
743 return 0; /* not enough buffer */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
744
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
745 /* do the real write-out */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
746 for (cur = *list; cur; cur = cur->next) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
747 aimbs_put16(bs, cur->tlv->type);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
748 aimbs_put16(bs, cur->tlv->length);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
749 if (cur->tlv->length)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
750 aimbs_putraw(bs, cur->tlv->value, cur->tlv->length);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
751 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
752
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
753 return 1; /* XXX this is a nonsensical return */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
754 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
755
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
756
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
757 /**
7166
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
758 * 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
759 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
760 * Returns a pointer to an aim_tlv_t of the specified type;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
761 * %NULL on error. The @nth parameter is specified starting at %1.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
762 * 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
763 * in a chain.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
764 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
765 * @param list Source chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
766 * @param type Requested TLV type.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
767 * @param nth Index of TLV of type to get.
7166
e6b01bd8d6cd [gaim-migrate @ 7733]
Mark Doliner <mark@kingant.net>
parents: 7158
diff changeset
768 * @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
769 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
770 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
771 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
772 aim_tlvlist_t *cur;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
773 int i;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
774
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
775 for (cur = list, i = 0; cur; cur = cur->next) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
776 if (cur && cur->tlv) {
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
777 if (cur->tlv->type == type)
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
778 i++;
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
779 if (i >= nth)
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
780 return cur->tlv;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
781 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
782 }
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
783
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
784 return NULL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
785 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
786
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
787 /**
9933
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
788 * 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
789 *
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
790 * @param list Source chain.
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
791 * @param type Requested TLV type.
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
792 * @param nth Index of TLV of type to get.
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
793 * @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
794 * found. Unless -1 is returned, this value will be 2 bytes.
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
795 */
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
796 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
797 {
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
798 aim_tlvlist_t *cur;
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
799 int i;
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
800
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
801 for (cur = list, i = 0; cur; cur = cur->next) {
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
802 if (cur && cur->tlv) {
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
803 if (cur->tlv->type == type)
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
804 i++;
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
805 if (i >= nth)
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
806 return cur->tlv->length;
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
807 }
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
808 }
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
809
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
810 return -1;
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
811 }
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
812
cee849d17167 [gaim-migrate @ 10825]
Mark Doliner <mark@kingant.net>
parents: 8794
diff changeset
813 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
814 * 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
815 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
816 * @param list Source TLV chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
817 * @param type TLV type to search for.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
818 * @param nth Index of TLV to return.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
819 * @return The value of the TLV you were looking for, or NULL if one could
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
820 * not be found. This is a dynamic buffer and must be freed by the
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
821 * caller.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
822 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
823 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
824 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
825 aim_tlv_t *tlv;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
826 char *newstr;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
827
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
828 if (!(tlv = aim_tlv_gettlv(list, type, nth)))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
829 return NULL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
830
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
831 newstr = (char *) malloc(tlv->length + 1);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
832 memcpy(newstr, tlv->value, tlv->length);
7011
4375bf2d9020 [gaim-migrate @ 7574]
Mark Doliner <mark@kingant.net>
parents: 6101
diff changeset
833 newstr[tlv->length] = '\0';
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
834
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
835 return newstr;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
836 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
837
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
838 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
839 * 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
840 * integer.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
841 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
842 * @param list Source TLV chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
843 * @param type TLV type to search for.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
844 * @param nth Index of TLV to return.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
845 * @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
846 * not be found.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
847 */
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
848 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
849 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
850 aim_tlv_t *tlv;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
851
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
852 if (!(tlv = aim_tlv_gettlv(list, type, nth)))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
853 return 0; /* erm */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
854 return aimutil_get8(tlv->value);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
855 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
856
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
857 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
858 * 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
859 * integer.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
860 *
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
861 * @param list Source TLV chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
862 * @param type TLV type to search for.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
863 * @param nth Index of TLV to return.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
864 * @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
865 * not be found.
2086
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 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
868 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
869 aim_tlv_t *tlv;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
870
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
871 if (!(tlv = aim_tlv_gettlv(list, type, nth)))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
872 return 0; /* erm */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
873 return aimutil_get16(tlv->value);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
874 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
875
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
876 /**
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
877 * 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
878 * integer.
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 * @param list Source TLV chain.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
881 * @param type TLV type to search for.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
882 * @param nth Index of TLV to return.
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
883 * @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
884 * not be found.
2086
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 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
887 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
888 aim_tlv_t *tlv;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
889
7167
6d3d8f11e765 [gaim-migrate @ 7734]
Mark Doliner <mark@kingant.net>
parents: 7166
diff changeset
890 if (!(tlv = aim_tlv_gettlv(list, type, nth)))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
891 return 0; /* erm */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
892 return aimutil_get32(tlv->value);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
893 }