annotate libfaim/aim_tlv.c @ 428:debb1c32def3

[gaim-migrate @ 438] Woo committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Fri, 23 Jun 2000 19:05:11 +0000
parents 0f14e6d8a51b
children 6d78b988b479
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
283
0f14e6d8a51b [gaim-migrate @ 293]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
1 #include <faim/aim.h>
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
3 struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
4 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
5 int pos;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
6 struct aim_tlvlist_t *list;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
7 struct aim_tlvlist_t *cur;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
8
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
9 u_short type;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
10 u_short length;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
11
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
12 if (!buf)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
13 return NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
14
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
15 list = NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
16
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
17 pos = 0;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
18
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
19 while (pos < maxlen)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
20 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
21 type = aimutil_get16(buf+pos);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
22 pos += 2;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
23
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
24 if (pos < maxlen)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
25 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
26 length = aimutil_get16(buf+pos);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
27 pos += 2;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
28
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
29 if ((pos+length) <= maxlen)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
30 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
31 cur = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
32 memset(cur, 0x00, sizeof(struct aim_tlvlist_t));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
33
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
34 cur->tlv = aim_createtlv();
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
35 cur->tlv->type = type;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
36 cur->tlv->length = length;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
37 cur->tlv->value = (u_char *)malloc(length*sizeof(u_char));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
38 memcpy(cur->tlv->value, buf+pos, length);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
39
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
40 cur->next = list;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
41 list = cur;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
42
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
43 pos += length;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
44 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
45 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
46 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
47
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
48 return list;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
49 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
50
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
51 void aim_freetlvchain(struct aim_tlvlist_t **list)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
52 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
53 struct aim_tlvlist_t *cur, *cur2;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
54
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
55 if (!list || !(*list))
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
56 return;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
57
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
58 cur = *list;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
59 while (cur)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
60 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
61 aim_freetlv(&cur->tlv);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
62 cur2 = cur->next;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
63 free(cur);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
64 cur = cur2;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
65 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
66 list = NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
67 return;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
68 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
69
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
70 int aim_counttlvchain(struct aim_tlvlist_t **list)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
71 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
72 struct aim_tlvlist_t *cur;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
73 int count = 0;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
74
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
75 if (!list || !(*list))
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
76 return 0;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
77
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
78 for (cur = *list; cur; cur = cur->next)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
79 count++;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
80
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
81 return count;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
82 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
83
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
84 int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
85 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
86 struct aim_tlvlist_t *new;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
87 struct aim_tlvlist_t *cur;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
88
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
89 if (!list)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
90 return 0;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
91
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
92 new = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
93 memset(new, 0x00, sizeof(struct aim_tlvlist_t));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
94
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
95 new->tlv = aim_createtlv();
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
96 new->tlv->type = type;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
97 new->tlv->length = len;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
98 new->tlv->value = (u_char *)malloc(new->tlv->length*sizeof(u_char));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
99 memcpy(new->tlv->value, str, new->tlv->length);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
100
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
101 new->next = NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
102
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
103 if (*list == NULL) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
104 *list = new;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
105 } else if ((*list)->next == NULL) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
106 (*list)->next = new;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
107 } else {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
108 for(cur = *list; cur->next; cur = cur->next)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
109 ;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
110 cur->next = new;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
111 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
112 return new->tlv->length;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
113 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
114
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
115 int aim_addtlvtochain16(struct aim_tlvlist_t **list, unsigned short type, unsigned short val)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
116 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
117 struct aim_tlvlist_t *new;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
118 struct aim_tlvlist_t *cur;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
119
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
120 if (!list)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
121 return 0;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
122
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
123 new = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
124 memset(new, 0x00, sizeof(struct aim_tlvlist_t));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
125
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
126 new->tlv = aim_createtlv();
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
127 new->tlv->type = type;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
128 new->tlv->length = 2;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
129 new->tlv->value = (u_char *)malloc(new->tlv->length*sizeof(u_char));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
130 aimutil_put16(new->tlv->value, val);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
131
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
132 new->next = NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
133
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
134 if (*list == NULL) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
135 *list = new;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
136 } else if ((*list)->next == NULL) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
137 (*list)->next = new;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
138 } else {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
139 for(cur = *list; cur->next; cur = cur->next)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
140 ;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
141 cur->next = new;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
142 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
143 return 2;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
144 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
145
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
146 int aim_addtlvtochain32(struct aim_tlvlist_t **list, unsigned short type, unsigned long val)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
147 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
148 struct aim_tlvlist_t *new;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
149 struct aim_tlvlist_t *cur;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
150
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
151 if (!list)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
152 return 0;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
153
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
154 new = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
155 memset(new, 0x00, sizeof(struct aim_tlvlist_t));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
156
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
157 new->tlv = aim_createtlv();
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
158 new->tlv->type = type;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
159 new->tlv->length = 4;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
160 new->tlv->value = (u_char *)malloc(new->tlv->length*sizeof(u_char));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
161 aimutil_put32(new->tlv->value, val);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
162
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
163 new->next = NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
164
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
165 if (*list == NULL) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
166 *list = new;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
167 } else if ((*list)->next == NULL) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
168 (*list)->next = new;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
169 } else {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
170 for(cur = *list; cur->next; cur = cur->next)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
171 ;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
172 cur->next = new;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
173 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
174 return 4;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
175 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
176
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
177 int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
178 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
179 int goodbuflen = 0;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
180 int i = 0;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
181 struct aim_tlvlist_t *cur;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
182
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
183 if (!list || !buf || !buflen)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
184 return 0;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
185
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
186 /* do an initial run to test total length */
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
187 for (cur = *list; cur; cur = cur->next) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
188 goodbuflen += 2 + 2; /* type + len */
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
189 goodbuflen += cur->tlv->length;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
190 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
191
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
192 if (goodbuflen > buflen)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
193 return 0; /* not enough buffer */
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
194
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
195 /* do the real write-out */
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
196 for (cur = *list; cur; cur = cur->next) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
197 i += aimutil_put16(buf+i, cur->tlv->type);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
198 i += aimutil_put16(buf+i, cur->tlv->length);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
199 memcpy(buf+i, cur->tlv->value, cur->tlv->length);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
200 i += cur->tlv->length;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
201 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
202
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
203 return i;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
204 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
205
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
206
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
207 /*
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
208 * Grab the Nth TLV of type type in the TLV list list.
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
209 */
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
210 struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *list, u_short type, int nth)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
211 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
212 int i;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
213 struct aim_tlvlist_t *cur;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
214
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
215 i = 0;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
216 for (cur = list; cur != NULL; cur = cur->next)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
217 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
218 if (cur && cur->tlv)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
219 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
220 if (cur->tlv->type == type)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
221 i++;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
222 if (i >= nth)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
223 return cur->tlv;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
224 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
225 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
226 return NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
227 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
228
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
229 char *aim_gettlv_str(struct aim_tlvlist_t *list, u_short type, int nth)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
230 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
231 struct aim_tlv_t *tlv;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
232 char *newstr;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
233
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
234 if (!(tlv = aim_gettlv(list, type, nth)))
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
235 return NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
236
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
237 newstr = (char *) malloc(tlv->length + 1);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
238 memcpy(newstr, tlv->value, tlv->length);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
239 *(newstr + tlv->length) = '\0';
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
240
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
241 return newstr;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
242 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
243
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
244 struct aim_tlv_t *aim_grabtlv(u_char *src)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
245 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
246 struct aim_tlv_t *dest = NULL;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
247
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
248 dest = aim_createtlv();
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
249
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
250 dest->type = src[0] << 8;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
251 dest->type += src[1];
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
252
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
253 dest->length = src[2] << 8;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
254 dest->length += src[3];
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
255
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
256 dest->value = (u_char *) malloc(dest->length*sizeof(u_char));
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
257 memset(dest->value, 0, dest->length*sizeof(u_char));
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
258
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
259 memcpy(dest->value, &(src[4]), dest->length*sizeof(u_char));
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
260
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
261 return dest;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
262 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
263
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
264 struct aim_tlv_t *aim_grabtlvstr(u_char *src)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
265 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
266 struct aim_tlv_t *dest = NULL;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
267
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
268 dest = aim_createtlv();
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
269
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
270 dest->type = src[0] << 8;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
271 dest->type += src[1];
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
272
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
273 dest->length = src[2] << 8;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
274 dest->length += src[3];
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
275
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
276 dest->value = (u_char *) malloc((dest->length+1)*sizeof(u_char));
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
277 memset(dest->value, 0, (dest->length+1)*sizeof(u_char));
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
278
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
279 memcpy(dest->value, &(src[4]), dest->length*sizeof(u_char));
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
280 dest->value[dest->length] = '\0';
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
281
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
282 return dest;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
283 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
284
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
285 int aim_puttlv (u_char *dest, struct aim_tlv_t *newtlv)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
286 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
287 int i=0;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
288
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
289 dest[i++] = newtlv->type >> 8;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
290 dest[i++] = newtlv->type & 0x00FF;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
291 dest[i++] = newtlv->length >> 8;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
292 dest[i++] = newtlv->length & 0x00FF;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
293 memcpy(&(dest[i]), newtlv->value, newtlv->length);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
294 i+=newtlv->length;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
295 return i;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
296 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
297
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
298 struct aim_tlv_t *aim_createtlv(void)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
299 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
300 struct aim_tlv_t *newtlv = NULL;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
301 newtlv = (struct aim_tlv_t *)malloc(sizeof(struct aim_tlv_t));
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
302 memset(newtlv, 0, sizeof(struct aim_tlv_t));
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
303 return newtlv;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
304 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
305
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
306 int aim_freetlv(struct aim_tlv_t **oldtlv)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
307 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
308 if (!oldtlv)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
309 return -1;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
310 if (!*oldtlv)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
311 return -1;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
312 if ((*oldtlv)->value)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
313 free((*oldtlv)->value);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
314 free(*(oldtlv));
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
315 (*oldtlv) = NULL;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
316
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
317 return 0;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
318 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
319
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
320 int aim_puttlv_16(u_char *buf, u_short t, u_short v)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
321 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
322 int curbyte=0;
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
323 curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
324 curbyte += aimutil_put16(buf+curbyte, (u_short)0x0002);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
325 curbyte += aimutil_put16(buf+curbyte, (u_short)(v&0xffff));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
326 return curbyte;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
327 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
328
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
329 int aim_puttlv_32(u_char *buf, u_short t, u_long v)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
330 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
331 int curbyte=0;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
332 curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
333 curbyte += aimutil_put16(buf+curbyte, (u_short)0x0004);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
334 curbyte += aimutil_put32(buf+curbyte, (u_long)(v&0xffffffff));
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
335 return curbyte;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
336 }
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
337
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
338 int aim_puttlv_str(u_char *buf, u_short t, u_short l, u_char *v)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
339 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
340 int curbyte;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
341
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
342 curbyte = 0;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
343 curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
344 curbyte += aimutil_put16(buf+curbyte, (u_short)(l&0xffff));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
345 if (v)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
346 memcpy(buf+curbyte, v, l);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
347 curbyte += l;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
348 return curbyte;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
349 }