comparison src/protocols/oscar/tlv.c @ 2270:d82efea341ef

[gaim-migrate @ 2280] new libfaim. stupid bugs. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Wed, 12 Sep 2001 00:39:51 +0000
parents 933346315b9b
children 95b4ec08abec
comparison
equal deleted inserted replaced
2269:7ff6170d84a0 2270:d82efea341ef
41 * element doesn't need to be malloc/memcpy'd. This could prove to be 41 * element doesn't need to be malloc/memcpy'd. This could prove to be
42 * just as effecient as the in-place TLV parsing used in a couple places 42 * just as effecient as the in-place TLV parsing used in a couple places
43 * in libfaim. 43 * in libfaim.
44 * 44 *
45 */ 45 */
46 faim_export aim_tlvlist_t *aim_readtlvchain(aim_bstream_t *bs) 46 faim_internal aim_tlvlist_t *aim_readtlvchain(aim_bstream_t *bs)
47 { 47 {
48 aim_tlvlist_t *list = NULL, *cur; 48 aim_tlvlist_t *list = NULL, *cur;
49 fu16_t type, length; 49 fu16_t type, length;
50 50
51 while (aim_bstream_empty(bs)) { 51 while (aim_bstream_empty(bs)) {
93 * Walks the list of TLVs in the passed TLV chain and 93 * Walks the list of TLVs in the passed TLV chain and
94 * frees each one. Note that any references to this data 94 * frees each one. Note that any references to this data
95 * should be removed before calling this. 95 * should be removed before calling this.
96 * 96 *
97 */ 97 */
98 faim_export void aim_freetlvchain(aim_tlvlist_t **list) 98 faim_internal void aim_freetlvchain(aim_tlvlist_t **list)
99 { 99 {
100 aim_tlvlist_t *cur; 100 aim_tlvlist_t *cur;
101 101
102 if (!list || !*list) 102 if (!list || !*list)
103 return; 103 return;
122 * @list: Chain to be counted 122 * @list: Chain to be counted
123 * 123 *
124 * Returns the number of TLVs stored in the passed chain. 124 * Returns the number of TLVs stored in the passed chain.
125 * 125 *
126 */ 126 */
127 faim_export int aim_counttlvchain(aim_tlvlist_t **list) 127 faim_internal int aim_counttlvchain(aim_tlvlist_t **list)
128 { 128 {
129 aim_tlvlist_t *cur; 129 aim_tlvlist_t *cur;
130 int count; 130 int count;
131 131
132 if (!list || !*list) 132 if (!list || !*list)
144 * 144 *
145 * Returns the number of bytes that would be needed to 145 * Returns the number of bytes that would be needed to
146 * write the passed TLV chain to a data buffer. 146 * write the passed TLV chain to a data buffer.
147 * 147 *
148 */ 148 */
149 faim_export int aim_sizetlvchain(aim_tlvlist_t **list) 149 faim_internal int aim_sizetlvchain(aim_tlvlist_t **list)
150 { 150 {
151 aim_tlvlist_t *cur; 151 aim_tlvlist_t *cur;
152 int size; 152 int size;
153 153
154 if (!list || !*list) 154 if (!list || !*list)
169 * 169 *
170 * Adds the passed string as a TLV element of the passed type 170 * Adds the passed string as a TLV element of the passed type
171 * to the TLV chain. 171 * to the TLV chain.
172 * 172 *
173 */ 173 */
174 faim_export int aim_addtlvtochain_raw(aim_tlvlist_t **list, const fu16_t t, const fu16_t l, const fu8_t *v) 174 faim_internal int aim_addtlvtochain_raw(aim_tlvlist_t **list, const fu16_t t, const fu16_t l, const fu8_t *v)
175 { 175 {
176 aim_tlvlist_t *newtlv, *cur; 176 aim_tlvlist_t *newtlv, *cur;
177 177
178 if (!list) 178 if (!list)
179 return 0; 179 return 0;
210 * @val: Value to add 210 * @val: Value to add
211 * 211 *
212 * Adds a two-byte unsigned integer to a TLV chain. 212 * Adds a two-byte unsigned integer to a TLV chain.
213 * 213 *
214 */ 214 */
215 faim_export int aim_addtlvtochain16(aim_tlvlist_t **list, const fu16_t t, const fu16_t v) 215 faim_internal int aim_addtlvtochain16(aim_tlvlist_t **list, const fu16_t t, const fu16_t v)
216 { 216 {
217 fu8_t v16[2]; 217 fu8_t v16[2];
218 218
219 aimutil_put16(v16, v); 219 aimutil_put16(v16, v);
220 220
228 * @val: Value to add 228 * @val: Value to add
229 * 229 *
230 * Adds a four-byte unsigned integer to a TLV chain. 230 * Adds a four-byte unsigned integer to a TLV chain.
231 * 231 *
232 */ 232 */
233 faim_export int aim_addtlvtochain32(aim_tlvlist_t **list, const fu16_t t, const fu32_t v) 233 faim_internal int aim_addtlvtochain32(aim_tlvlist_t **list, const fu16_t t, const fu32_t v)
234 { 234 {
235 fu8_t v32[4]; 235 fu8_t v32[4];
236 236
237 aimutil_put32(v32, v); 237 aimutil_put32(v32, v);
238 238
259 * %AIM_CAPS_GETFILE Supports Get File functions 259 * %AIM_CAPS_GETFILE Supports Get File functions
260 * 260 *
261 * %AIM_CAPS_SENDFILE Supports Send File functions 261 * %AIM_CAPS_SENDFILE Supports Send File functions
262 * 262 *
263 */ 263 */
264 faim_export int aim_addtlvtochain_caps(aim_tlvlist_t **list, const fu16_t t, const fu16_t caps) 264 faim_internal int aim_addtlvtochain_caps(aim_tlvlist_t **list, const fu16_t t, const fu16_t caps)
265 { 265 {
266 fu8_t buf[16*16]; /* icky fixed length buffer */ 266 fu8_t buf[16*16]; /* icky fixed length buffer */
267 aim_bstream_t bs; 267 aim_bstream_t bs;
268 268
269 aim_bstream_init(&bs, buf, sizeof(buf)); 269 aim_bstream_init(&bs, buf, sizeof(buf));
270 270
271 aim_putcap(&bs, caps); 271 aim_putcap(&bs, caps);
272 272
273 return aim_addtlvtochain_raw(list, t, aim_bstream_curpos(&bs), buf); 273 return aim_addtlvtochain_raw(list, t, aim_bstream_curpos(&bs), buf);
274 }
275
276 faim_internal int aim_addtlvtochain_userinfo(aim_tlvlist_t **list, fu16_t type, struct aim_userinfo_s *ui)
277 {
278 fu8_t buf[1024]; /* bleh */
279 aim_bstream_t bs;
280
281 aim_bstream_init(&bs, buf, sizeof(buf));
282
283 aim_putuserinfo(&bs, ui);
284
285 return aim_addtlvtochain_raw(list, type, aim_bstream_curpos(&bs), buf);
274 } 286 }
275 287
276 /** 288 /**
277 * aim_addtlvtochain_noval - Add a blank TLV to a TLV chain 289 * aim_addtlvtochain_noval - Add a blank TLV to a TLV chain
278 * @list: Destination chain 290 * @list: Destination chain
332 * aim_freetlvchain() must still be called to free up the memory used 344 * aim_freetlvchain() must still be called to free up the memory used
333 * by the chain structures. 345 * by the chain structures.
334 * 346 *
335 * XXX clean this up, make better use of bstreams 347 * XXX clean this up, make better use of bstreams
336 */ 348 */
337 faim_export int aim_writetlvchain(aim_bstream_t *bs, aim_tlvlist_t **list) 349 faim_internal int aim_writetlvchain(aim_bstream_t *bs, aim_tlvlist_t **list)
338 { 350 {
339 int goodbuflen; 351 int goodbuflen;
340 aim_tlvlist_t *cur; 352 aim_tlvlist_t *cur;
341 353
342 /* do an initial run to test total length */ 354 /* do an initial run to test total length */
370 * %NULL on error. The @nth parameter is specified starting at %1. 382 * %NULL on error. The @nth parameter is specified starting at %1.
371 * In most cases, there will be no more than one TLV of any type 383 * In most cases, there will be no more than one TLV of any type
372 * in a chain. 384 * in a chain.
373 * 385 *
374 */ 386 */
375 faim_export aim_tlv_t *aim_gettlv(aim_tlvlist_t *list, const fu16_t t, const int n) 387 faim_internal aim_tlv_t *aim_gettlv(aim_tlvlist_t *list, const fu16_t t, const int n)
376 { 388 {
377 aim_tlvlist_t *cur; 389 aim_tlvlist_t *cur;
378 int i; 390 int i;
379 391
380 for (cur = list, i = 0; cur; cur = cur->next) { 392 for (cur = list, i = 0; cur; cur = cur->next) {
398 * Same as aim_gettlv(), except that the return value is a %NULL- 410 * Same as aim_gettlv(), except that the return value is a %NULL-
399 * terminated string instead of an aim_tlv_t. This is a 411 * terminated string instead of an aim_tlv_t. This is a
400 * dynamic buffer and must be freed by the caller. 412 * dynamic buffer and must be freed by the caller.
401 * 413 *
402 */ 414 */
403 faim_export char *aim_gettlv_str(aim_tlvlist_t *list, const fu16_t t, const int n) 415 faim_internal char *aim_gettlv_str(aim_tlvlist_t *list, const fu16_t t, const int n)
404 { 416 {
405 aim_tlv_t *tlv; 417 aim_tlv_t *tlv;
406 char *newstr; 418 char *newstr;
407 419
408 if (!(tlv = aim_gettlv(list, t, n))) 420 if (!(tlv = aim_gettlv(list, t, n)))