2
|
1 #include <aim.h>
|
|
2
|
|
3 struct aim_tlv_t *aim_grabtlv(u_char *src)
|
|
4 {
|
|
5 struct aim_tlv_t *dest = NULL;
|
|
6
|
|
7 dest = aim_createtlv();
|
|
8
|
|
9 dest->type = src[0] << 8;
|
|
10 dest->type += src[1];
|
|
11
|
|
12 dest->length = src[2] << 8;
|
|
13 dest->length += src[3];
|
|
14
|
|
15 dest->value = (u_char *) malloc(dest->length*sizeof(u_char));
|
|
16 memset(dest->value, 0, dest->length*sizeof(u_char));
|
|
17
|
|
18 memcpy(dest->value, &(src[4]), dest->length*sizeof(u_char));
|
|
19
|
|
20 return dest;
|
|
21 }
|
|
22
|
|
23 struct aim_tlv_t *aim_grabtlvstr(u_char *src)
|
|
24 {
|
|
25 struct aim_tlv_t *dest = NULL;
|
|
26
|
|
27 dest = aim_createtlv();
|
|
28
|
|
29 dest->type = src[0] << 8;
|
|
30 dest->type += src[1];
|
|
31
|
|
32 dest->length = src[2] << 8;
|
|
33 dest->length += src[3];
|
|
34
|
|
35 dest->value = (u_char *) malloc((dest->length+1)*sizeof(u_char));
|
|
36 memset(dest->value, 0, (dest->length+1)*sizeof(u_char));
|
|
37
|
|
38 memcpy(dest->value, &(src[4]), dest->length*sizeof(u_char));
|
|
39 dest->value[dest->length] = '\0';
|
|
40
|
|
41 return dest;
|
|
42 }
|
|
43
|
|
44 int aim_puttlv (u_char *dest, struct aim_tlv_t *newtlv)
|
|
45 {
|
|
46 int i=0;
|
|
47
|
|
48 dest[i++] = newtlv->type >> 8;
|
|
49 dest[i++] = newtlv->type & 0x00FF;
|
|
50 dest[i++] = newtlv->length >> 8;
|
|
51 dest[i++] = newtlv->length & 0x00FF;
|
|
52 memcpy(&(dest[i]), newtlv->value, newtlv->length);
|
|
53 i+=newtlv->length;
|
|
54 return i;
|
|
55 }
|
|
56
|
|
57 struct aim_tlv_t *aim_createtlv(void)
|
|
58 {
|
|
59 struct aim_tlv_t *newtlv = NULL;
|
|
60 newtlv = (struct aim_tlv_t *)malloc(sizeof(struct aim_tlv_t));
|
|
61 memset(newtlv, 0, sizeof(struct aim_tlv_t));
|
|
62 return newtlv;
|
|
63 }
|
|
64
|
|
65 int aim_freetlv(struct aim_tlv_t **oldtlv)
|
|
66 {
|
|
67 if (!oldtlv)
|
|
68 return -1;
|
|
69 if (!*oldtlv)
|
|
70 return -1;
|
|
71 if ((*oldtlv)->value)
|
|
72 free((*oldtlv)->value);
|
|
73 free(*(oldtlv));
|
|
74 (*oldtlv) = NULL;
|
|
75
|
|
76 return 0;
|
|
77 }
|
|
78
|
|
79 int aim_puttlv_16(u_char *buf, u_short t, u_short v)
|
|
80 {
|
|
81 int curbyte=0;
|
|
82 curbyte += aimutil_put16(buf+curbyte, t&0xffff);
|
|
83 curbyte += aimutil_put16(buf+curbyte, 0x0002);
|
|
84 curbyte += aimutil_put16(buf+curbyte, v&0xffff);
|
|
85 return curbyte;
|
|
86 }
|