Mercurial > pidgin.yaz
comparison libfaim/aim_tlv.c @ 840:595ac7759563
[gaim-migrate @ 850]
lots of (mostly useless for us) libfaim changes. should help portability, but it was always portable between unices.... stupid win32ers.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Mon, 04 Sep 2000 23:37:32 +0000 |
parents | f425f51a3db8 |
children | e1da6a6ec42b |
comparison
equal
deleted
inserted
replaced
839:8f66e00af045 | 840:595ac7759563 |
---|---|
1 #include <faim/aim.h> | 1 #include <faim/aim.h> |
2 | 2 |
3 struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen) | 3 faim_internal struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen) |
4 { | 4 { |
5 int pos; | 5 int pos; |
6 struct aim_tlvlist_t *list; | 6 struct aim_tlvlist_t *list; |
7 struct aim_tlvlist_t *cur; | 7 struct aim_tlvlist_t *cur; |
8 | 8 |
60 } | 60 } |
61 | 61 |
62 return list; | 62 return list; |
63 } | 63 } |
64 | 64 |
65 void aim_freetlvchain(struct aim_tlvlist_t **list) | 65 faim_internal void aim_freetlvchain(struct aim_tlvlist_t **list) |
66 { | 66 { |
67 struct aim_tlvlist_t *cur, *cur2; | 67 struct aim_tlvlist_t *cur, *cur2; |
68 | 68 |
69 if (!list || !(*list)) | 69 if (!list || !(*list)) |
70 return; | 70 return; |
79 } | 79 } |
80 list = NULL; | 80 list = NULL; |
81 return; | 81 return; |
82 } | 82 } |
83 | 83 |
84 int aim_counttlvchain(struct aim_tlvlist_t **list) | 84 faim_internal int aim_counttlvchain(struct aim_tlvlist_t **list) |
85 { | 85 { |
86 struct aim_tlvlist_t *cur; | 86 struct aim_tlvlist_t *cur; |
87 int count = 0; | 87 int count = 0; |
88 | 88 |
89 if (!list || !(*list)) | 89 if (!list || !(*list)) |
93 count++; | 93 count++; |
94 | 94 |
95 return count; | 95 return count; |
96 } | 96 } |
97 | 97 |
98 int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len) | 98 faim_internal int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len) |
99 { | 99 { |
100 struct aim_tlvlist_t *new; | 100 struct aim_tlvlist_t *new; |
101 struct aim_tlvlist_t *cur; | 101 struct aim_tlvlist_t *cur; |
102 | 102 |
103 if (!list) | 103 if (!list) |
124 cur->next = new; | 124 cur->next = new; |
125 } | 125 } |
126 return new->tlv->length; | 126 return new->tlv->length; |
127 } | 127 } |
128 | 128 |
129 int aim_addtlvtochain16(struct aim_tlvlist_t **list, unsigned short type, unsigned short val) | 129 faim_internal int aim_addtlvtochain16(struct aim_tlvlist_t **list, unsigned short type, unsigned short val) |
130 { | 130 { |
131 struct aim_tlvlist_t *new; | 131 struct aim_tlvlist_t *new; |
132 struct aim_tlvlist_t *cur; | 132 struct aim_tlvlist_t *cur; |
133 | 133 |
134 if (!list) | 134 if (!list) |
155 cur->next = new; | 155 cur->next = new; |
156 } | 156 } |
157 return 2; | 157 return 2; |
158 } | 158 } |
159 | 159 |
160 int aim_addtlvtochain32(struct aim_tlvlist_t **list, unsigned short type, unsigned long val) | 160 faim_internal int aim_addtlvtochain32(struct aim_tlvlist_t **list, unsigned short type, unsigned long val) |
161 { | 161 { |
162 struct aim_tlvlist_t *new; | 162 struct aim_tlvlist_t *new; |
163 struct aim_tlvlist_t *cur; | 163 struct aim_tlvlist_t *cur; |
164 | 164 |
165 if (!list) | 165 if (!list) |
186 cur->next = new; | 186 cur->next = new; |
187 } | 187 } |
188 return 4; | 188 return 4; |
189 } | 189 } |
190 | 190 |
191 int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list) | 191 faim_internal int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list) |
192 { | 192 { |
193 int goodbuflen = 0; | 193 int goodbuflen = 0; |
194 int i = 0; | 194 int i = 0; |
195 struct aim_tlvlist_t *cur; | 195 struct aim_tlvlist_t *cur; |
196 | 196 |
219 | 219 |
220 | 220 |
221 /* | 221 /* |
222 * Grab the Nth TLV of type type in the TLV list list. | 222 * Grab the Nth TLV of type type in the TLV list list. |
223 */ | 223 */ |
224 struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *list, u_short type, int nth) | 224 faim_internal struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *list, u_short type, int nth) |
225 { | 225 { |
226 int i; | 226 int i; |
227 struct aim_tlvlist_t *cur; | 227 struct aim_tlvlist_t *cur; |
228 | 228 |
229 i = 0; | 229 i = 0; |
238 } | 238 } |
239 } | 239 } |
240 return NULL; | 240 return NULL; |
241 } | 241 } |
242 | 242 |
243 char *aim_gettlv_str(struct aim_tlvlist_t *list, u_short type, int nth) | 243 faim_internal char *aim_gettlv_str(struct aim_tlvlist_t *list, u_short type, int nth) |
244 { | 244 { |
245 struct aim_tlv_t *tlv; | 245 struct aim_tlv_t *tlv; |
246 char *newstr; | 246 char *newstr; |
247 | 247 |
248 if (!(tlv = aim_gettlv(list, type, nth))) | 248 if (!(tlv = aim_gettlv(list, type, nth))) |
253 *(newstr + tlv->length) = '\0'; | 253 *(newstr + tlv->length) = '\0'; |
254 | 254 |
255 return newstr; | 255 return newstr; |
256 } | 256 } |
257 | 257 |
258 struct aim_tlv_t *aim_grabtlv(u_char *src) | 258 faim_internal struct aim_tlv_t *aim_grabtlv(u_char *src) |
259 { | 259 { |
260 struct aim_tlv_t *dest = NULL; | 260 struct aim_tlv_t *dest = NULL; |
261 | 261 |
262 dest = aim_createtlv(); | 262 dest = aim_createtlv(); |
263 | 263 |
273 memcpy(dest->value, &(src[4]), dest->length*sizeof(u_char)); | 273 memcpy(dest->value, &(src[4]), dest->length*sizeof(u_char)); |
274 | 274 |
275 return dest; | 275 return dest; |
276 } | 276 } |
277 | 277 |
278 struct aim_tlv_t *aim_grabtlvstr(u_char *src) | 278 faim_internal struct aim_tlv_t *aim_grabtlvstr(u_char *src) |
279 { | 279 { |
280 struct aim_tlv_t *dest = NULL; | 280 struct aim_tlv_t *dest = NULL; |
281 | 281 |
282 dest = aim_createtlv(); | 282 dest = aim_createtlv(); |
283 | 283 |
294 dest->value[dest->length] = '\0'; | 294 dest->value[dest->length] = '\0'; |
295 | 295 |
296 return dest; | 296 return dest; |
297 } | 297 } |
298 | 298 |
299 int aim_puttlv (u_char *dest, struct aim_tlv_t *newtlv) | 299 faim_internal int aim_puttlv(u_char *dest, struct aim_tlv_t *newtlv) |
300 { | 300 { |
301 int i=0; | 301 int i=0; |
302 | 302 |
303 dest[i++] = newtlv->type >> 8; | 303 dest[i++] = newtlv->type >> 8; |
304 dest[i++] = newtlv->type & 0x00FF; | 304 dest[i++] = newtlv->type & 0x00FF; |
307 memcpy(&(dest[i]), newtlv->value, newtlv->length); | 307 memcpy(&(dest[i]), newtlv->value, newtlv->length); |
308 i+=newtlv->length; | 308 i+=newtlv->length; |
309 return i; | 309 return i; |
310 } | 310 } |
311 | 311 |
312 struct aim_tlv_t *aim_createtlv(void) | 312 faim_internal struct aim_tlv_t *aim_createtlv(void) |
313 { | 313 { |
314 struct aim_tlv_t *newtlv = NULL; | 314 struct aim_tlv_t *newtlv = NULL; |
315 newtlv = (struct aim_tlv_t *)malloc(sizeof(struct aim_tlv_t)); | 315 newtlv = (struct aim_tlv_t *)malloc(sizeof(struct aim_tlv_t)); |
316 memset(newtlv, 0, sizeof(struct aim_tlv_t)); | 316 memset(newtlv, 0, sizeof(struct aim_tlv_t)); |
317 return newtlv; | 317 return newtlv; |
318 } | 318 } |
319 | 319 |
320 int aim_freetlv(struct aim_tlv_t **oldtlv) | 320 faim_internal int aim_freetlv(struct aim_tlv_t **oldtlv) |
321 { | 321 { |
322 if (!oldtlv) | 322 if (!oldtlv) |
323 return -1; | 323 return -1; |
324 if (!*oldtlv) | 324 if (!*oldtlv) |
325 return -1; | 325 return -1; |
329 (*oldtlv) = NULL; | 329 (*oldtlv) = NULL; |
330 | 330 |
331 return 0; | 331 return 0; |
332 } | 332 } |
333 | 333 |
334 int aim_puttlv_16(u_char *buf, u_short t, u_short v) | 334 faim_internal int aim_puttlv_16(u_char *buf, u_short t, u_short v) |
335 { | 335 { |
336 int curbyte=0; | 336 int curbyte=0; |
337 curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff)); | 337 curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff)); |
338 curbyte += aimutil_put16(buf+curbyte, (u_short)0x0002); | 338 curbyte += aimutil_put16(buf+curbyte, (u_short)0x0002); |
339 curbyte += aimutil_put16(buf+curbyte, (u_short)(v&0xffff)); | 339 curbyte += aimutil_put16(buf+curbyte, (u_short)(v&0xffff)); |
340 return curbyte; | 340 return curbyte; |
341 } | 341 } |
342 | 342 |
343 int aim_puttlv_32(u_char *buf, u_short t, u_long v) | 343 faim_internal int aim_puttlv_32(u_char *buf, u_short t, u_long v) |
344 { | 344 { |
345 int curbyte=0; | 345 int curbyte=0; |
346 curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff)); | 346 curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff)); |
347 curbyte += aimutil_put16(buf+curbyte, (u_short)0x0004); | 347 curbyte += aimutil_put16(buf+curbyte, (u_short)0x0004); |
348 curbyte += aimutil_put32(buf+curbyte, (u_long)(v&0xffffffff)); | 348 curbyte += aimutil_put32(buf+curbyte, (u_long)(v&0xffffffff)); |
349 return curbyte; | 349 return curbyte; |
350 } | 350 } |
351 | 351 |
352 int aim_puttlv_str(u_char *buf, u_short t, u_short l, u_char *v) | 352 faim_internal int aim_puttlv_str(u_char *buf, u_short t, u_short l, char *v) |
353 { | 353 { |
354 int curbyte; | 354 int curbyte; |
355 | 355 |
356 curbyte = 0; | 356 curbyte = 0; |
357 curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff)); | 357 curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff)); |
358 curbyte += aimutil_put16(buf+curbyte, (u_short)(l&0xffff)); | 358 curbyte += aimutil_put16(buf+curbyte, (u_short)(l&0xffff)); |
359 if (v) | 359 if (v) |
360 memcpy(buf+curbyte, v, l); | 360 memcpy(buf+curbyte, (unsigned char *)v, l); |
361 curbyte += l; | 361 curbyte += l; |
362 return curbyte; | 362 return curbyte; |
363 } | 363 } |