Mercurial > pidgin.yaz
annotate src/protocols/oscar/tlv.c @ 7166:e6b01bd8d6cd
[gaim-migrate @ 7733]
I fixed the notify_added function, Chip had two of the variables swapped :-)
I changed the way tlvlists are done in ssi.c a little bit. You can alias
ICQ buddies that you don't have authorization for yet, and when you alias
a buddy you will no longer lose any Buddy Alerts that may be set.
Why is this? Previously tlvlists (data associated with each server stored
item) were just deleted and recreated when you set an alias, or changed your
permit/deny setting. Now the lists are modified and TLVs that libfaim
doesn't know about are just left in place.
Why did I wait so long to do this? I'm lazy, it's not really all that fun,
and I don't consider it all that important.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 05 Oct 2003 22:41:29 +0000 |
parents | aee5fd893aba |
children | 6d3d8f11e765 |
rev | line source |
---|---|
2086 | 1 |
2 #define FAIM_INTERNAL | |
3 #include <aim.h> | |
4 | |
7158 | 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 | 7 aim_tlv_t *ret; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
8 |
7158 | 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 | 11 ret->type = type; |
12 ret->length = length; | |
13 ret->value = value; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
14 |
7158 | 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 | 31 /** |
32 * aim_readtlvchain - Read a TLV chain from a buffer. | |
33 * | |
34 * Reads and parses a series of TLV patterns from a data buffer; the | |
35 * returned structure is manipulatable with the rest of the TLV | |
36 * routines. When done with a TLV chain, aim_freetlvchain() should | |
37 * be called to free the dynamic substructures. | |
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 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
42 * just as effecient as the in-place TLV parsing used in a couple places |
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 | 45 * @param bs Input bstream |
2086 | 46 */ |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
47 faim_internal aim_tlvlist_t *aim_readtlvchain(aim_bstream_t *bs) |
2086 | 48 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
49 aim_tlvlist_t *list = NULL, *cur; |
3459 | 50 |
51 while (aim_bstream_empty(bs) > 0) { | |
52 fu16_t type, length; | |
2086 | 53 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
54 type = aimbs_get16(bs); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
55 length = aimbs_get16(bs); |
2086 | 56 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
57 #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
|
58 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
59 * Okay, so now AOL has decided that any TLV of |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
60 * type 0x0013 can only be two bytes, despite |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
61 * what the actual given length is. So here |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
62 * we dump any invalid TLVs of that sort. Hopefully |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
63 * theres no special cases to this special case. |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
64 * - mid (30jun2000) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
65 */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
66 if ((type == 0x0013) && (length != 0x0002)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
67 length = 0x0002; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
68 #else |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
69 if (0) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
70 ; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
71 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
72 else { |
2086 | 73 |
3459 | 74 if (length > aim_bstream_empty(bs)) { |
75 aim_freetlvchain(&list); | |
76 return NULL; | |
77 } | |
78 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
79 cur = (aim_tlvlist_t *)malloc(sizeof(aim_tlvlist_t)); |
3459 | 80 if (!cur) { |
81 aim_freetlvchain(&list); | |
82 return NULL; | |
83 } | |
84 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
85 memset(cur, 0, sizeof(aim_tlvlist_t)); |
2086 | 86 |
7158 | 87 cur->tlv = createtlv(type, length, NULL); |
3459 | 88 if (!cur->tlv) { |
89 free(cur); | |
90 aim_freetlvchain(&list); | |
91 return NULL; | |
92 } | |
7158 | 93 if (cur->tlv->length > 0) { |
94 cur->tlv->value = aimbs_getraw(bs, length); | |
95 if (!cur->tlv->value) { | |
96 freetlv(&cur->tlv); | |
97 free(cur); | |
98 aim_freetlvchain(&list); | |
99 return NULL; | |
100 } | |
3459 | 101 } |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
102 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
103 cur->next = list; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
104 list = cur; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
105 } |
2086 | 106 } |
107 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
108 return list; |
2086 | 109 } |
110 | |
111 /** | |
3952 | 112 * aim_readtlvchain_num - Read a TLV chain from a buffer. |
4230 | 113 * |
3952 | 114 * Reads and parses a series of TLV patterns from a data buffer; the |
115 * returned structure is manipulatable with the rest of the TLV | |
116 * routines. When done with a TLV chain, aim_freetlvchain() should | |
117 * be called to free the dynamic substructures. | |
118 * | |
119 * XXX There should be a flag setable here to have the tlvlist contain | |
120 * bstream references, so that at least the ->value portion of each | |
121 * element doesn't need to be malloc/memcpy'd. This could prove to be | |
122 * just as effecient as the in-place TLV parsing used in a couple places | |
123 * in libfaim. | |
124 * | |
7158 | 125 * @param bs Input bstream |
126 * @param num The max number of TLVs that will be read, or -1 if unlimited. | |
127 * There are a number of places where you want to read in a tlvchain, | |
128 * but the chain is not at the end of the SNAC, and the chain is | |
129 * preceeded by the number of TLVs. So you can limit that with this. | |
3952 | 130 */ |
131 faim_internal aim_tlvlist_t *aim_readtlvchain_num(aim_bstream_t *bs, fu16_t num) | |
132 { | |
133 aim_tlvlist_t *list = NULL, *cur; | |
4317 | 134 |
3952 | 135 while ((aim_bstream_empty(bs) > 0) && (num != 0)) { |
136 fu16_t type, length; | |
137 | |
138 type = aimbs_get16(bs); | |
139 length = aimbs_get16(bs); | |
140 | |
141 if (length > aim_bstream_empty(bs)) { | |
142 aim_freetlvchain(&list); | |
143 return NULL; | |
144 } | |
145 | |
146 cur = (aim_tlvlist_t *)malloc(sizeof(aim_tlvlist_t)); | |
147 if (!cur) { | |
148 aim_freetlvchain(&list); | |
149 return NULL; | |
150 } | |
151 | |
152 memset(cur, 0, sizeof(aim_tlvlist_t)); | |
153 | |
7158 | 154 cur->tlv = createtlv(type, length, NULL); |
3952 | 155 if (!cur->tlv) { |
156 free(cur); | |
157 aim_freetlvchain(&list); | |
158 return NULL; | |
159 } | |
7158 | 160 if (cur->tlv->length > 0) { |
161 cur->tlv->value = aimbs_getraw(bs, length); | |
162 if (!cur->tlv->value) { | |
163 freetlv(&cur->tlv); | |
164 free(cur); | |
165 aim_freetlvchain(&list); | |
166 return NULL; | |
167 } | |
3952 | 168 } |
169 | |
7158 | 170 if (num > 0) |
171 num--; | |
3952 | 172 cur->next = list; |
173 list = cur; | |
174 } | |
175 | |
176 return list; | |
177 } | |
178 | |
179 /** | |
4317 | 180 * aim_readtlvchain_len - Read a TLV chain from a buffer. |
4230 | 181 * |
182 * Reads and parses a series of TLV patterns from a data buffer; the | |
183 * returned structure is manipulatable with the rest of the TLV | |
184 * routines. When done with a TLV chain, aim_freetlvchain() should | |
185 * be called to free the dynamic substructures. | |
186 * | |
187 * XXX There should be a flag setable here to have the tlvlist contain | |
188 * bstream references, so that at least the ->value portion of each | |
189 * element doesn't need to be malloc/memcpy'd. This could prove to be | |
190 * just as effecient as the in-place TLV parsing used in a couple places | |
191 * in libfaim. | |
192 * | |
7158 | 193 * @param bs Input bstream |
194 * @param len The max length in bytes that will be read. | |
195 * There are a number of places where you want to read in a tlvchain, | |
196 * but the chain is not at the end of the SNAC, and the chain is | |
197 * preceeded by the length of the TLVs. So you can limit that with this. | |
4230 | 198 */ |
199 faim_internal aim_tlvlist_t *aim_readtlvchain_len(aim_bstream_t *bs, fu16_t len) | |
200 { | |
201 aim_tlvlist_t *list = NULL, *cur; | |
4317 | 202 |
4230 | 203 while ((aim_bstream_empty(bs) > 0) && (len > 0)) { |
204 fu16_t type, length; | |
205 | |
206 type = aimbs_get16(bs); | |
207 length = aimbs_get16(bs); | |
208 | |
209 if (length > aim_bstream_empty(bs)) { | |
210 aim_freetlvchain(&list); | |
211 return NULL; | |
212 } | |
213 | |
214 cur = (aim_tlvlist_t *)malloc(sizeof(aim_tlvlist_t)); | |
215 if (!cur) { | |
216 aim_freetlvchain(&list); | |
217 return NULL; | |
218 } | |
219 | |
220 memset(cur, 0, sizeof(aim_tlvlist_t)); | |
221 | |
7158 | 222 cur->tlv = createtlv(type, length, NULL); |
4230 | 223 if (!cur->tlv) { |
224 free(cur); | |
225 aim_freetlvchain(&list); | |
226 return NULL; | |
227 } | |
7158 | 228 if (cur->tlv->length > 0) { |
229 cur->tlv->value = aimbs_getraw(bs, length); | |
230 if (!cur->tlv->value) { | |
231 freetlv(&cur->tlv); | |
232 free(cur); | |
233 aim_freetlvchain(&list); | |
234 return NULL; | |
235 } | |
4230 | 236 } |
237 | |
238 len -= aim_sizetlvchain(&cur); | |
239 cur->next = list; | |
240 list = cur; | |
241 } | |
242 | |
243 return list; | |
244 } | |
245 | |
246 /** | |
247 * aim_tlvlist_copy - Duplicate a TLV chain. | |
248 * This is pretty pelf exslanatory. | |
249 * | |
7158 | 250 * @param orig The TLV chain you want to make a copy of. |
251 * @return A newly allocated TLV chain. | |
4230 | 252 */ |
253 faim_internal aim_tlvlist_t *aim_tlvlist_copy(aim_tlvlist_t *orig) | |
254 { | |
255 aim_tlvlist_t *new = NULL; | |
256 | |
257 while (orig) { | |
258 aim_addtlvtochain_raw(&new, orig->tlv->type, orig->tlv->length, orig->tlv->value); | |
259 orig = orig->next; | |
260 } | |
261 | |
262 return new; | |
263 } | |
264 | |
6101 | 265 /* |
266 * Compare two TLV lists for equality. This probably is not the most | |
267 * efficient way to do this. | |
268 * | |
269 * @param one One of the TLV chains to compare. | |
270 * @param two The other TLV chain to compare. | |
271 * @preturn Retrun 0 if the lists are the same, return 1 if they are different. | |
272 */ | |
273 faim_internal int aim_tlvlist_cmp(aim_tlvlist_t *one, aim_tlvlist_t *two) | |
274 { | |
275 aim_bstream_t bs1, bs2; | |
276 | |
277 if (aim_sizetlvchain(&one) != aim_sizetlvchain(&two)) | |
278 return 1; | |
279 | |
280 aim_bstream_init(&bs1, ((fu8_t *)malloc(aim_sizetlvchain(&one)*sizeof(fu8_t))), aim_sizetlvchain(&one)); | |
281 aim_bstream_init(&bs2, ((fu8_t *)malloc(aim_sizetlvchain(&two)*sizeof(fu8_t))), aim_sizetlvchain(&two)); | |
282 | |
283 aim_writetlvchain(&bs1, &one); | |
284 aim_writetlvchain(&bs2, &two); | |
285 | |
286 if (memcmp(bs1.data, bs2.data, bs1.len)) { | |
287 free(bs1.data); | |
288 free(bs2.data); | |
289 return 1; | |
290 } | |
291 | |
292 free(bs1.data); | |
293 free(bs2.data); | |
294 | |
295 return 0; | |
296 } | |
297 | |
4230 | 298 /** |
2086 | 299 * aim_freetlvchain - Free a TLV chain structure |
300 * @list: Chain to be freed | |
301 * | |
302 * Walks the list of TLVs in the passed TLV chain and | |
303 * frees each one. Note that any references to this data | |
304 * should be removed before calling this. | |
305 * | |
306 */ | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
307 faim_internal void aim_freetlvchain(aim_tlvlist_t **list) |
2086 | 308 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
309 aim_tlvlist_t *cur; |
2086 | 310 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
311 if (!list || !*list) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
312 return; |
2086 | 313 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
314 for (cur = *list; cur; ) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
315 aim_tlvlist_t *tmp; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
316 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
317 freetlv(&cur->tlv); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
318 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
319 tmp = cur->next; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
320 free(cur); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
321 cur = tmp; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
322 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
323 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
324 list = NULL; |
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 return; |
2086 | 327 } |
328 | |
329 /** | |
330 * aim_counttlvchain - Count the number of TLVs in a chain | |
331 * @list: Chain to be counted | |
332 * | |
333 * Returns the number of TLVs stored in the passed chain. | |
334 * | |
335 */ | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
336 faim_internal int aim_counttlvchain(aim_tlvlist_t **list) |
2086 | 337 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
338 aim_tlvlist_t *cur; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
339 int count; |
2086 | 340 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
341 if (!list || !*list) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
342 return 0; |
2086 | 343 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
344 for (cur = *list, count = 0; cur; cur = cur->next) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
345 count++; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
346 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
347 return count; |
2086 | 348 } |
349 | |
350 /** | |
351 * aim_sizetlvchain - Count the number of bytes in a TLV chain | |
352 * @list: Chain to be sized | |
353 * | |
354 * Returns the number of bytes that would be needed to | |
355 * write the passed TLV chain to a data buffer. | |
356 * | |
357 */ | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
358 faim_internal int aim_sizetlvchain(aim_tlvlist_t **list) |
2086 | 359 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
360 aim_tlvlist_t *cur; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
361 int size; |
2086 | 362 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
363 if (!list || !*list) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
364 return 0; |
2086 | 365 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
366 for (cur = *list, size = 0; cur; cur = cur->next) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
367 size += (4 + cur->tlv->length); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
368 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
369 return size; |
2086 | 370 } |
371 | |
372 /** | |
3912 | 373 * aim_addtlvtochain_raw - Add a string to a TLV chain |
2086 | 374 * |
375 * Adds the passed string as a TLV element of the passed type | |
376 * to the TLV chain. | |
377 * | |
7166 | 378 * @param list Desination chain (%NULL pointer if empty) |
379 * @param type TLV type | |
380 * @length Length of string to add (not including %NULL) | |
381 * @value String to add | |
2086 | 382 */ |
7158 | 383 faim_internal int aim_addtlvtochain_raw(aim_tlvlist_t **list, const fu16_t type, const fu16_t length, const fu8_t *value) |
2086 | 384 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
385 aim_tlvlist_t *newtlv, *cur; |
2086 | 386 |
7166 | 387 if (list == NULL) |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
388 return 0; |
2086 | 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 | 393 |
7158 | 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 | 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 | 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 | 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 | 412 } |
413 | |
414 /** | |
2821
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
415 * aim_addtlvtochain8 - Add a 8bit integer to a TLV chain |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
416 * @list: Destination chain |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
417 * @type: TLV type to add |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
418 * @val: Value to add |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
419 * |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
420 * Adds a one-byte unsigned integer to a TLV chain. |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
421 * |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
422 */ |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
423 faim_internal int aim_addtlvtochain8(aim_tlvlist_t **list, const fu16_t t, const fu8_t v) |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
424 { |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
425 fu8_t v8[1]; |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
426 |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
427 aimutil_put8(v8, v); |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
428 |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
429 return aim_addtlvtochain_raw(list, t, 1, v8); |
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 |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2421
diff
changeset
|
432 /** |
2086 | 433 * aim_addtlvtochain16 - Add a 16bit integer to a TLV chain |
434 * @list: Destination chain | |
3952 | 435 * @t: TLV type to add |
436 * @v: Value to add | |
2086 | 437 * |
438 * Adds a two-byte unsigned integer to a TLV chain. | |
439 * | |
440 */ | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
441 faim_internal int aim_addtlvtochain16(aim_tlvlist_t **list, const fu16_t t, const fu16_t v) |
2086 | 442 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
443 fu8_t v16[2]; |
2086 | 444 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
445 aimutil_put16(v16, v); |
2086 | 446 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
447 return aim_addtlvtochain_raw(list, t, 2, v16); |
2086 | 448 } |
449 | |
450 /** | |
451 * aim_addtlvtochain32 - Add a 32bit integer to a TLV chain | |
452 * @list: Destination chain | |
453 * @type: TLV type to add | |
454 * @val: Value to add | |
455 * | |
456 * Adds a four-byte unsigned integer to a TLV chain. | |
457 * | |
458 */ | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
459 faim_internal int aim_addtlvtochain32(aim_tlvlist_t **list, const fu16_t t, const fu32_t v) |
2086 | 460 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
461 fu8_t v32[4]; |
2086 | 462 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
463 aimutil_put32(v32, v); |
2086 | 464 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
465 return aim_addtlvtochain_raw(list, t, 4, v32); |
2086 | 466 } |
467 | |
468 /** | |
469 * aim_addtlvtochain_caps - Add a capability block to a TLV chain | |
470 * | |
471 * Adds a block of capability blocks to a TLV chain. The bitfield | |
472 * passed in should be a bitwise %OR of any of the %AIM_CAPS constants: | |
473 * | |
7158 | 474 * %AIM_CAPS_BUDDYICON Supports Buddy Icons |
475 * %AIM_CAPS_VOICE Supports Voice Chat | |
476 * %AIM_CAPS_IMIMAGE Supports DirectIM/IMImage | |
477 * %AIM_CAPS_CHAT Supports Chat | |
478 * %AIM_CAPS_GETFILE Supports Get File functions | |
479 * %AIM_CAPS_SENDFILE Supports Send File functions | |
2086 | 480 * |
7158 | 481 * @param list Destination chain |
482 * @param type TLV type to add | |
483 * @param caps Bitfield of capability flags to send | |
2086 | 484 */ |
2866
6d62d4520460
[gaim-migrate @ 2879]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2821
diff
changeset
|
485 faim_internal int aim_addtlvtochain_caps(aim_tlvlist_t **list, const fu16_t t, const fu32_t caps) |
2086 | 486 { |
2866
6d62d4520460
[gaim-migrate @ 2879]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2821
diff
changeset
|
487 fu8_t buf[16*16]; /* XXX icky fixed length buffer */ |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
488 aim_bstream_t bs; |
2086 | 489 |
2421
95b4ec08abec
[gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2270
diff
changeset
|
490 if (!caps) |
95b4ec08abec
[gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2270
diff
changeset
|
491 return 0; /* nothing there anyway */ |
95b4ec08abec
[gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2270
diff
changeset
|
492 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
493 aim_bstream_init(&bs, buf, sizeof(buf)); |
2086 | 494 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
495 aim_putcap(&bs, caps); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
496 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
497 return aim_addtlvtochain_raw(list, t, aim_bstream_curpos(&bs), buf); |
2086 | 498 } |
499 | |
2421
95b4ec08abec
[gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2270
diff
changeset
|
500 faim_internal int aim_addtlvtochain_userinfo(aim_tlvlist_t **list, fu16_t type, aim_userinfo_t *ui) |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
501 { |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
502 fu8_t buf[1024]; /* bleh */ |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
503 aim_bstream_t bs; |
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 aim_bstream_init(&bs, buf, sizeof(buf)); |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
506 |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
507 aim_putuserinfo(&bs, ui); |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
508 |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
509 return aim_addtlvtochain_raw(list, type, aim_bstream_curpos(&bs), buf); |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
510 } |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
511 |
2086 | 512 /** |
513 * aim_addtlvtochain_noval - Add a blank TLV to a TLV chain | |
514 * @list: Destination chain | |
515 * @type: TLV type to add | |
516 * | |
517 * Adds a TLV with a zero length to a TLV chain. | |
518 * | |
519 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
520 faim_internal int aim_addtlvtochain_noval(aim_tlvlist_t **list, const fu16_t t) |
2086 | 521 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
522 return aim_addtlvtochain_raw(list, t, 0, NULL); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
523 } |
2086 | 524 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
525 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
526 * 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
|
527 * 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
|
528 * made to this. |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
529 * |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
530 * XXX should probably support sublists for real. |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
531 * |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
532 * This is so neat. |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
533 * |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
534 */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
535 faim_internal int aim_addtlvtochain_frozentlvlist(aim_tlvlist_t **list, fu16_t type, aim_tlvlist_t **tl) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
536 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
537 fu8_t *buf; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
538 int buflen; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
539 aim_bstream_t bs; |
2086 | 540 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
541 buflen = aim_sizetlvchain(tl); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
542 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
543 if (buflen <= 0) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
544 return 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
545 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
546 if (!(buf = malloc(buflen))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
547 return 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
548 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
549 aim_bstream_init(&bs, buf, buflen); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
550 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
551 aim_writetlvchain(&bs, tl); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
552 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
553 aim_addtlvtochain_raw(list, type, aim_bstream_curpos(&bs), buf); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
554 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
555 free(buf); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
556 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
557 return buflen; |
2086 | 558 } |
559 | |
560 /** | |
7166 | 561 * Substitute a TLV of a given type with a new TLV of the same type. If |
562 * you attempt to replace a TLV that does not exist, this function will | |
563 * just add a new TLV as if you called aim_addtlvtochain_raw(). | |
564 * | |
565 * @param list Desination chain (%NULL pointer if empty). | |
566 * @param type TLV type. | |
567 * @param length Length of string to add (not including %NULL). | |
568 * @param value String to add. | |
569 * @return The length of the TLV. | |
570 */ | |
571 faim_internal int aim_tlvlist_replace_raw(aim_tlvlist_t **list, const fu16_t type, const fu16_t length, const fu8_t *value) | |
572 { | |
573 aim_tlvlist_t *cur; | |
574 | |
575 if (list == NULL) | |
576 return 0; | |
577 | |
578 for (cur = *list; ((cur != NULL) && (cur->tlv->type != type)); cur = cur->next); | |
579 if (cur == NULL) | |
580 return aim_addtlvtochain_raw(list, type, length, value); | |
581 | |
582 free(cur->tlv->value); | |
583 cur->tlv->length = length; | |
584 if (cur->tlv->length > 0) { | |
585 cur->tlv->value = (fu8_t *)malloc(cur->tlv->length); | |
586 memcpy(cur->tlv->value, value, cur->tlv->length); | |
587 } else | |
588 cur->tlv->value = NULL; | |
589 | |
590 return cur->tlv->length; | |
591 } | |
592 | |
593 /** | |
594 * Substitute a TLV of a given type with a new TLV of the same type. If | |
595 * you attempt to replace a TLV that does not exist, this function will | |
596 * just add a new TLV as if you called aim_addtlvtochain_raw(). | |
597 * | |
598 * @param list Desination chain (%NULL pointer if empty). | |
599 * @param type TLV type. | |
600 * @return The length of the TLV. | |
601 */ | |
602 faim_internal int aim_tlvlist_replace_noval(aim_tlvlist_t **list, const fu16_t type) | |
603 { | |
604 return aim_tlvlist_replace_raw(list, type, 0, NULL); | |
605 } | |
606 | |
607 /** | |
608 * Substitute a TLV of a given type with a new TLV of the same type. If | |
609 * you attempt to replace a TLV that does not exist, this function will | |
610 * just add a new TLV as if you called aim_addtlvtochain_raw(). | |
611 * | |
612 * @param list Desination chain (%NULL pointer if empty). | |
613 * @param type TLV type. | |
614 * @param value 8 bit value to add. | |
615 * @return The length of the TLV. | |
616 */ | |
617 faim_internal int aim_tlvlist_replace_8(aim_tlvlist_t **list, const fu16_t type, const fu8_t value) | |
618 { | |
619 fu8_t v8[1]; | |
620 | |
621 aimutil_put8(v8, value); | |
622 | |
623 return aim_tlvlist_replace_raw(list, type, 1, v8); | |
624 } | |
625 | |
626 /** | |
627 * Substitute a TLV of a given type with a new TLV of the same type. If | |
628 * you attempt to replace a TLV that does not exist, this function will | |
629 * just add a new TLV as if you called aim_addtlvtochain_raw(). | |
630 * | |
631 * @param list Desination chain (%NULL pointer if empty). | |
632 * @param type TLV type. | |
633 * @param value 32 bit value to add. | |
634 * @return The length of the TLV. | |
635 */ | |
636 faim_internal int aim_tlvlist_replace_32(aim_tlvlist_t **list, const fu16_t type, const fu32_t value) | |
637 { | |
638 fu8_t v32[4]; | |
639 | |
640 aimutil_put32(v32, value); | |
641 | |
642 return aim_tlvlist_replace_raw(list, type, 4, v32); | |
643 } | |
644 | |
645 /** | |
646 * Remove a TLV of a given type. If you attempt to remove a TLV that | |
647 * does not exist, nothing happens. | |
648 * | |
649 * @param list Desination chain (%NULL pointer if empty). | |
650 * @param type TLV type. | |
651 */ | |
652 faim_internal void aim_tlvlist_remove(aim_tlvlist_t **list, const fu16_t type) | |
653 { | |
654 aim_tlvlist_t *del; | |
655 | |
656 if (!list || !(*list)) | |
657 return; | |
658 | |
659 /* Remove the item from the list */ | |
660 if ((*list)->tlv->type == type) { | |
661 del = *list; | |
662 *list = (*list)->next; | |
663 } else { | |
664 aim_tlvlist_t *cur; | |
665 for (cur=*list; (cur->next && (cur->next->tlv->type!=type)); cur=cur->next); | |
666 if (!cur->next) | |
667 return; | |
668 del = cur->next; | |
669 cur->next = del->next; | |
670 } | |
671 | |
672 /* Free the removed item */ | |
673 free(del->tlv->value); | |
674 free(del->tlv); | |
675 free(del); | |
676 } | |
677 | |
678 /** | |
2086 | 679 * aim_writetlvchain - Write a TLV chain into a data buffer. |
680 * @buf: Destination buffer | |
681 * @buflen: Maximum number of bytes that will be written to buffer | |
682 * @list: Source TLV chain | |
683 * | |
684 * Copies a TLV chain into a raw data buffer, writing only the number | |
685 * of bytes specified. This operation does not free the chain; | |
686 * aim_freetlvchain() must still be called to free up the memory used | |
687 * by the chain structures. | |
688 * | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
689 * XXX clean this up, make better use of bstreams |
2086 | 690 */ |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
691 faim_internal int aim_writetlvchain(aim_bstream_t *bs, aim_tlvlist_t **list) |
2086 | 692 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
693 int goodbuflen; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
694 aim_tlvlist_t *cur; |
2086 | 695 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
696 /* do an initial run to test total length */ |
4617 | 697 goodbuflen = aim_sizetlvchain(list); |
2086 | 698 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
699 if (goodbuflen > aim_bstream_empty(bs)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
700 return 0; /* not enough buffer */ |
2086 | 701 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
702 /* do the real write-out */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
703 for (cur = *list; cur; cur = cur->next) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
704 aimbs_put16(bs, cur->tlv->type); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
705 aimbs_put16(bs, cur->tlv->length); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
706 if (cur->tlv->length) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
707 aimbs_putraw(bs, cur->tlv->value, cur->tlv->length); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
708 } |
2086 | 709 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
710 return 1; /* XXX this is a nonsensical return */ |
2086 | 711 } |
712 | |
713 | |
714 /** | |
7166 | 715 * Grab the Nth TLV of type type in the TLV list list. |
2086 | 716 * |
717 * Returns a pointer to an aim_tlv_t of the specified type; | |
718 * %NULL on error. The @nth parameter is specified starting at %1. | |
719 * In most cases, there will be no more than one TLV of any type | |
720 * in a chain. | |
721 * | |
7166 | 722 * @param list Source chain |
723 * @param type Requested TLV type | |
724 * @param nth Index of TLV of type to get | |
725 * @return The TLV you were looking for, or NULL if one could not be found. | |
2086 | 726 */ |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
727 faim_internal aim_tlv_t *aim_gettlv(aim_tlvlist_t *list, const fu16_t t, const int n) |
2086 | 728 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
729 aim_tlvlist_t *cur; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
730 int i; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
731 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
732 for (cur = list, i = 0; cur; cur = cur->next) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
733 if (cur && cur->tlv) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
734 if (cur->tlv->type == t) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
735 i++; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
736 if (i >= n) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
737 return cur->tlv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
738 } |
2086 | 739 } |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
740 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
741 return NULL; |
2086 | 742 } |
743 | |
744 /** | |
745 * aim_gettlv_str - Retrieve the Nth TLV in chain as a string. | |
746 * @list: Source TLV chain | |
747 * @type: TLV type to search for | |
748 * @nth: Index of TLV to return | |
749 * | |
750 * Same as aim_gettlv(), except that the return value is a %NULL- | |
751 * terminated string instead of an aim_tlv_t. This is a | |
752 * dynamic buffer and must be freed by the caller. | |
753 * | |
754 */ | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
755 faim_internal char *aim_gettlv_str(aim_tlvlist_t *list, const fu16_t t, const int n) |
2086 | 756 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
757 aim_tlv_t *tlv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
758 char *newstr; |
2086 | 759 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
760 if (!(tlv = aim_gettlv(list, t, n))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
761 return NULL; |
2086 | 762 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
763 newstr = (char *) malloc(tlv->length + 1); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
764 memcpy(newstr, tlv->value, tlv->length); |
7011 | 765 newstr[tlv->length] = '\0'; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
766 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
767 return newstr; |
2086 | 768 } |
769 | |
770 /** | |
771 * aim_gettlv8 - Retrieve the Nth TLV in chain as a 8bit integer. | |
772 * @list: Source TLV chain | |
773 * @type: TLV type to search for | |
774 * @nth: Index of TLV to return | |
775 * | |
776 * Same as aim_gettlv(), except that the return value is a | |
777 * 8bit integer instead of an aim_tlv_t. | |
778 * | |
779 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
780 faim_internal fu8_t aim_gettlv8(aim_tlvlist_t *list, const fu16_t t, const int n) |
2086 | 781 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
782 aim_tlv_t *tlv; |
2086 | 783 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
784 if (!(tlv = aim_gettlv(list, t, n))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
785 return 0; /* erm */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
786 return aimutil_get8(tlv->value); |
2086 | 787 } |
788 | |
789 /** | |
790 * aim_gettlv16 - Retrieve the Nth TLV in chain as a 16bit integer. | |
791 * @list: Source TLV chain | |
792 * @type: TLV type to search for | |
793 * @nth: Index of TLV to return | |
794 * | |
795 * Same as aim_gettlv(), except that the return value is a | |
796 * 16bit integer instead of an aim_tlv_t. | |
797 * | |
798 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
799 faim_internal fu16_t aim_gettlv16(aim_tlvlist_t *list, const fu16_t t, const int n) |
2086 | 800 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
801 aim_tlv_t *tlv; |
2086 | 802 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
803 if (!(tlv = aim_gettlv(list, t, n))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
804 return 0; /* erm */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
805 return aimutil_get16(tlv->value); |
2086 | 806 } |
807 | |
808 /** | |
809 * aim_gettlv32 - Retrieve the Nth TLV in chain as a 32bit integer. | |
810 * @list: Source TLV chain | |
811 * @type: TLV type to search for | |
812 * @nth: Index of TLV to return | |
813 * | |
814 * Same as aim_gettlv(), except that the return value is a | |
815 * 32bit integer instead of an aim_tlv_t. | |
816 * | |
817 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
818 faim_internal fu32_t aim_gettlv32(aim_tlvlist_t *list, const fu16_t t, const int n) |
2086 | 819 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
820 aim_tlv_t *tlv; |
2086 | 821 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
822 if (!(tlv = aim_gettlv(list, t, n))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
823 return 0; /* erm */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
824 return aimutil_get32(tlv->value); |
2086 | 825 } |
826 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
827 #if 0 |
2086 | 828 /** |
829 * aim_puttlv_8 - Write a one-byte TLV. | |
830 * @buf: Destination buffer | |
831 * @t: TLV type | |
832 * @v: Value | |
833 * | |
834 * Writes a TLV with a one-byte integer value portion. | |
835 * | |
836 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
837 faim_export int aim_puttlv_8(fu8_t *buf, const fu16_t t, const fu8_t v) |
2086 | 838 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
839 fu8_t v8[1]; |
2086 | 840 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
841 aimutil_put8(v8, v); |
2086 | 842 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
843 return aim_puttlv_raw(buf, t, 1, v8); |
2086 | 844 } |
845 | |
846 /** | |
847 * aim_puttlv_16 - Write a two-byte TLV. | |
848 * @buf: Destination buffer | |
849 * @t: TLV type | |
850 * @v: Value | |
851 * | |
852 * Writes a TLV with a two-byte integer value portion. | |
853 * | |
854 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
855 faim_export int aim_puttlv_16(fu8_t *buf, const fu16_t t, const fu16_t v) |
2086 | 856 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
857 fu8_t v16[2]; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
858 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
859 aimutil_put16(v16, v); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
860 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
861 return aim_puttlv_raw(buf, t, 2, v16); |
2086 | 862 } |
863 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
864 |
2086 | 865 /** |
866 * aim_puttlv_32 - Write a four-byte TLV. | |
867 * @buf: Destination buffer | |
868 * @t: TLV type | |
869 * @v: Value | |
870 * | |
871 * Writes a TLV with a four-byte integer value portion. | |
872 * | |
873 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
874 faim_export int aim_puttlv_32(fu8_t *buf, const fu16_t t, const fu32_t v) |
2086 | 875 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
876 fu8_t v32[4]; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
877 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
878 aimutil_put32(v32, v); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
879 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
880 return aim_puttlv_raw(buf, t, 4, v32); |
2086 | 881 } |
882 | |
883 /** | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
884 * aim_puttlv_raw - Write a raw TLV. |
2086 | 885 * @buf: Destination buffer |
886 * @t: TLV type | |
887 * @l: Length of string | |
888 * @v: String to write | |
889 * | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
890 * Writes a TLV with a raw value portion. (Only the first @l |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
891 * bytes of the passed buffer will be written, which should not |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
892 * include a terminating NULL.) |
2086 | 893 * |
894 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
895 faim_export int aim_puttlv_raw(fu8_t *buf, const fu16_t t, const fu16_t l, const fu8_t *v) |
2086 | 896 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
897 int i; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
898 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
899 i = aimutil_put16(buf, t); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
900 i += aimutil_put16(buf+i, l); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
901 if (l) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
902 memcpy(buf+i, v, l); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
903 i += l; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
904 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
905 return i; |
2086 | 906 } |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
907 #endif |