Mercurial > pidgin.yaz
annotate libfaim/aim_tlv.c @ 1254:9da444224f0e
[gaim-migrate @ 1264]
bmiller's away-on-signon patch. does --away=mesg use "mesg" or the away message titled "mesg"? i didn't look hehe. but if it uses "mesg" instead of the away message titled "mesg" then i'm not sure it works.... i figured someone would report a bug if it didn't work
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Thu, 14 Dec 2000 00:11:59 +0000 |
parents | 2ac6ccb94229 |
children |
rev | line source |
---|---|
283
0f14e6d8a51b
[gaim-migrate @ 293]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
237
diff
changeset
|
1 #include <faim/aim.h> |
2 | 2 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
3 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
4 * aim_readtlvchain - Read a TLV chain from a buffer. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
5 * @buf: Input buffer |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
6 * @maxlen: Length of input buffer |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
7 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
8 * Reads and parses a series of TLV patterns from a data buffer; the |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
9 * returned structure is manipulatable with the rest of the TLV |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
10 * routines. When done with a TLV chain, aim_freetlvchain() should |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
11 * be called to free the dynamic substructures. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
12 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
13 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
14 faim_export struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen) |
237 | 15 { |
16 int pos; | |
17 struct aim_tlvlist_t *list; | |
18 struct aim_tlvlist_t *cur; | |
19 | |
20 u_short type; | |
21 u_short length; | |
22 | |
23 if (!buf) | |
24 return NULL; | |
25 | |
26 list = NULL; | |
27 | |
28 pos = 0; | |
29 | |
30 while (pos < maxlen) | |
31 { | |
32 type = aimutil_get16(buf+pos); | |
33 pos += 2; | |
34 | |
35 if (pos < maxlen) | |
36 { | |
37 length = aimutil_get16(buf+pos); | |
38 pos += 2; | |
39 | |
40 if ((pos+length) <= maxlen) | |
41 { | |
446
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
42 /* |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
43 * Okay, so now AOL has decided that any TLV of |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
44 * type 0x0013 can only be two bytes, despite |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
45 * what the actual given length is. So here |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
46 * we dump any invalid TLVs of that sort. Hopefully |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
47 * theres no special cases to this special case. |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
48 * - mid (30jun2000) |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
49 */ |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
50 if ((type == 0x0013) && (length != 0x0002)) { |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
51 printf("faim: skipping TLV t(0013) with invalid length (0x%04x)\n", length); |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
52 length = 0x0002; |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
53 } else { |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
54 cur = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t)); |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
55 memset(cur, 0x00, sizeof(struct aim_tlvlist_t)); |
237 | 56 |
446
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
57 cur->tlv = aim_createtlv(); |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
58 cur->tlv->type = type; |
818
f425f51a3db8
[gaim-migrate @ 828]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
771
diff
changeset
|
59 cur->tlv->length = length; |
f425f51a3db8
[gaim-migrate @ 828]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
771
diff
changeset
|
60 if (length) { |
f425f51a3db8
[gaim-migrate @ 828]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
771
diff
changeset
|
61 cur->tlv->value = (unsigned char *)malloc(length); |
f425f51a3db8
[gaim-migrate @ 828]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
771
diff
changeset
|
62 memcpy(cur->tlv->value, buf+pos, length); |
f425f51a3db8
[gaim-migrate @ 828]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
771
diff
changeset
|
63 } |
771
72e556f6b99d
[gaim-migrate @ 781]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
446
diff
changeset
|
64 |
446
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
65 cur->next = list; |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
66 list = cur; |
6d78b988b479
[gaim-migrate @ 456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
67 } |
237 | 68 pos += length; |
69 } | |
70 } | |
71 } | |
72 | |
73 return list; | |
74 } | |
75 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
76 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
77 * aim_freetlvchain - Free a TLV chain structure |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
78 * @list: Chain to be freed |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
79 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
80 * Walks the list of TLVs in the passed TLV chain and |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
81 * frees each one. Note that any references to this data |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
82 * should be removed before calling this. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
83 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
84 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
85 faim_export void aim_freetlvchain(struct aim_tlvlist_t **list) |
237 | 86 { |
87 struct aim_tlvlist_t *cur, *cur2; | |
88 | |
89 if (!list || !(*list)) | |
90 return; | |
91 | |
92 cur = *list; | |
93 while (cur) | |
94 { | |
95 aim_freetlv(&cur->tlv); | |
96 cur2 = cur->next; | |
97 free(cur); | |
98 cur = cur2; | |
99 } | |
100 list = NULL; | |
101 return; | |
102 } | |
103 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
104 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
105 * aim_counttlvchain - Count the number of TLVs in a chain |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
106 * @list: Chain to be counted |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
107 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
108 * Returns the number of TLVs stored in the passed chain. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
109 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
110 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
111 faim_export int aim_counttlvchain(struct aim_tlvlist_t **list) |
237 | 112 { |
113 struct aim_tlvlist_t *cur; | |
114 int count = 0; | |
115 | |
116 if (!list || !(*list)) | |
117 return 0; | |
118 | |
119 for (cur = *list; cur; cur = cur->next) | |
120 count++; | |
121 | |
122 return count; | |
123 } | |
124 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
125 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
126 * aim_sizetlvchain - Count the number of bytes in a TLV chain |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
127 * @list: Chain to be sized |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
128 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
129 * Returns the number of bytes that would be needed to |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
130 * write the passed TLV chain to a data buffer. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
131 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
132 */ |
1002
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
133 faim_export int aim_sizetlvchain(struct aim_tlvlist_t **list) |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
134 { |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
135 struct aim_tlvlist_t *cur; |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
136 int size = 0; |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
137 |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
138 if (!list || !(*list)) |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
139 return 0; |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
140 |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
141 for (cur = *list; cur; cur = cur->next) |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
142 size += (4 + cur->tlv->length); |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
143 |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
144 return size; |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
145 } |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
146 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
147 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
148 * aim_addtlvtochain_str - Add a string to a TLV chain |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
149 * @list: Desination chain (%NULL pointer if empty) |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
150 * @type: TLV type |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
151 * @str: String to add |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
152 * @len: Length of string to add (not including %NULL) |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
153 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
154 * Adds the passed string as a TLV element of the passed type |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
155 * to the TLV chain. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
156 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
157 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
158 faim_export int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len) |
237 | 159 { |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
160 struct aim_tlvlist_t *newtlv; |
237 | 161 struct aim_tlvlist_t *cur; |
162 | |
163 if (!list) | |
164 return 0; | |
165 | |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
166 newtlv = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t)); |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
167 memset(newtlv, 0x00, sizeof(struct aim_tlvlist_t)); |
237 | 168 |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
169 newtlv->tlv = aim_createtlv(); |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
170 newtlv->tlv->type = type; |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
171 newtlv->tlv->length = len; |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
172 newtlv->tlv->value = (unsigned char *)malloc(newtlv->tlv->length*sizeof(unsigned char)); |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
173 memcpy(newtlv->tlv->value, str, newtlv->tlv->length); |
237 | 174 |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
175 newtlv->next = NULL; |
237 | 176 |
177 if (*list == NULL) { | |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
178 *list = newtlv; |
237 | 179 } else if ((*list)->next == NULL) { |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
180 (*list)->next = newtlv; |
237 | 181 } else { |
182 for(cur = *list; cur->next; cur = cur->next) | |
183 ; | |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
184 cur->next = newtlv; |
237 | 185 } |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
186 return newtlv->tlv->length; |
237 | 187 } |
188 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
189 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
190 * aim_addtlvtochain16 - Add a 16bit integer to a TLV chain |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
191 * @list: Destination chain |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
192 * @type: TLV type to add |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
193 * @val: Value to add |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
194 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
195 * Adds a two-byte unsigned integer to a TLV chain. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
196 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
197 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
198 faim_export int aim_addtlvtochain16(struct aim_tlvlist_t **list, unsigned short type, unsigned short val) |
237 | 199 { |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
200 struct aim_tlvlist_t *newtl; |
237 | 201 struct aim_tlvlist_t *cur; |
202 | |
203 if (!list) | |
204 return 0; | |
205 | |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
206 newtl = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t)); |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
207 memset(newtl, 0x00, sizeof(struct aim_tlvlist_t)); |
237 | 208 |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
209 newtl->tlv = aim_createtlv(); |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
210 newtl->tlv->type = type; |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
211 newtl->tlv->length = 2; |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
212 newtl->tlv->value = (unsigned char *)malloc(newtl->tlv->length*sizeof(unsigned char)); |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
213 aimutil_put16(newtl->tlv->value, val); |
237 | 214 |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
215 newtl->next = NULL; |
237 | 216 |
217 if (*list == NULL) { | |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
218 *list = newtl; |
237 | 219 } else if ((*list)->next == NULL) { |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
220 (*list)->next = newtl; |
237 | 221 } else { |
222 for(cur = *list; cur->next; cur = cur->next) | |
223 ; | |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
224 cur->next = newtl; |
237 | 225 } |
226 return 2; | |
227 } | |
228 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
229 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
230 * aim_addtlvtochain32 - Add a 32bit integer to a TLV chain |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
231 * @list: Destination chain |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
232 * @type: TLV type to add |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
233 * @val: Value to add |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
234 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
235 * Adds a four-byte unsigned integer to a TLV chain. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
236 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
237 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
238 faim_export int aim_addtlvtochain32(struct aim_tlvlist_t **list, unsigned short type, unsigned long val) |
237 | 239 { |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
240 struct aim_tlvlist_t *newtl; |
237 | 241 struct aim_tlvlist_t *cur; |
242 | |
243 if (!list) | |
244 return 0; | |
245 | |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
246 newtl = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t)); |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
247 memset(newtl, 0x00, sizeof(struct aim_tlvlist_t)); |
237 | 248 |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
249 newtl->tlv = aim_createtlv(); |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
250 newtl->tlv->type = type; |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
251 newtl->tlv->length = 4; |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
252 newtl->tlv->value = (unsigned char *)malloc(newtl->tlv->length*sizeof(unsigned char)); |
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
253 aimutil_put32(newtl->tlv->value, val); |
237 | 254 |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
255 newtl->next = NULL; |
237 | 256 |
257 if (*list == NULL) { | |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
258 *list = newtl; |
237 | 259 } else if ((*list)->next == NULL) { |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
260 (*list)->next = newtl; |
237 | 261 } else { |
262 for(cur = *list; cur->next; cur = cur->next) | |
263 ; | |
900
e18815f5a4e9
[gaim-migrate @ 910]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
264 cur->next = newtl; |
237 | 265 } |
266 return 4; | |
267 } | |
268 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
269 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
270 * aim_addtlvtochain_caps - Add a capability block to a TLV chain |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
271 * @list: Destination chain |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
272 * @type: TLV type to add |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
273 * @caps: Bitfield of capability flags to send |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
274 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
275 * Adds a block of capability blocks to a TLV chain. The bitfield |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
276 * passed in should be a bitwise %OR of any of the %AIM_CAPS constants: |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
277 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
278 * %AIM_CAPS_BUDDYICON Supports Buddy Icons |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
279 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
280 * %AIM_CAPS_VOICE Supports Voice Chat |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
281 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
282 * %AIM_CAPS_IMIMAGE Supports DirectIM/IMImage |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
283 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
284 * %AIM_CAPS_CHAT Supports Chat |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
285 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
286 * %AIM_CAPS_GETFILE Supports Get File functions |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
287 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
288 * %AIM_CAPS_SENDFILE Supports Send File functions |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
289 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
290 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
291 faim_export int aim_addtlvtochain_caps(struct aim_tlvlist_t **list, unsigned short type, unsigned short caps) |
1002
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
292 { |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
293 unsigned char buf[128]; /* icky fixed length buffer */ |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
294 struct aim_tlvlist_t *newtl; |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
295 struct aim_tlvlist_t *cur; |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
296 |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
297 if(!list) |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
298 return 0; |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
299 |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
300 newtl = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t)); |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
301 memset(newtl, 0x00, sizeof(struct aim_tlvlist_t)); |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
302 |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
303 newtl->tlv = aim_createtlv(); |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
304 newtl->tlv->type = type; |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
305 |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
306 newtl->tlv->length = aim_putcap(buf, sizeof(buf), caps); |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
307 newtl->tlv->value = (unsigned char *)calloc(1, newtl->tlv->length); |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
308 memcpy(newtl->tlv->value, buf, newtl->tlv->length); |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
309 |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
310 newtl->next = NULL; |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
311 |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
312 if (*list == NULL) { |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
313 *list = newtl; |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
314 } else if ((*list)->next == NULL) { |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
315 (*list)->next = newtl; |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
316 } else { |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
317 for(cur = *list; cur->next; cur = cur->next) |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
318 ; |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
319 cur->next = newtl; |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
320 } |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
321 return newtl->tlv->length; |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
322 } |
1d8f05ea6bdf
[gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
900
diff
changeset
|
323 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
324 /** |
1245
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
325 * aim_addtlvtochain_noval - Add a blank TLV to a TLV chain |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
326 * @list: Destination chain |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
327 * @type: TLV type to add |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
328 * |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
329 * Adds a TLV with a zero length to a TLV chain. |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
330 * |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
331 */ |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
332 faim_internal int aim_addtlvtochain_noval(struct aim_tlvlist_t **list, unsigned short type) |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
333 { |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
334 struct aim_tlvlist_t *newtlv; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
335 struct aim_tlvlist_t *cur; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
336 |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
337 newtlv = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t)); |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
338 memset(newtlv, 0x00, sizeof(struct aim_tlvlist_t)); |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
339 |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
340 newtlv->tlv = aim_createtlv(); |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
341 newtlv->tlv->type = type; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
342 newtlv->tlv->length = 0; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
343 newtlv->tlv->value = NULL; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
344 |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
345 newtlv->next = NULL; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
346 |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
347 if (*list == NULL) { |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
348 *list = newtlv; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
349 } else if ((*list)->next == NULL) { |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
350 (*list)->next = newtlv; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
351 } else { |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
352 for(cur = *list; cur->next; cur = cur->next) |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
353 ; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
354 cur->next = newtlv; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
355 } |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
356 return newtlv->tlv->length; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
357 } |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
358 |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
359 /** |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
360 * aim_writetlvchain - Write a TLV chain into a data buffer. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
361 * @buf: Destination buffer |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
362 * @buflen: Maximum number of bytes that will be written to buffer |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
363 * @list: Source TLV chain |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
364 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
365 * Copies a TLV chain into a raw data buffer, writing only the number |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
366 * of bytes specified. This operation does not free the chain; |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
367 * aim_freetlvchain() must still be called to free up the memory used |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
368 * by the chain structures. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
369 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
370 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
371 faim_export int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list) |
237 | 372 { |
373 int goodbuflen = 0; | |
374 int i = 0; | |
375 struct aim_tlvlist_t *cur; | |
376 | |
377 if (!list || !buf || !buflen) | |
378 return 0; | |
379 | |
380 /* do an initial run to test total length */ | |
381 for (cur = *list; cur; cur = cur->next) { | |
382 goodbuflen += 2 + 2; /* type + len */ | |
383 goodbuflen += cur->tlv->length; | |
384 } | |
385 | |
386 if (goodbuflen > buflen) | |
387 return 0; /* not enough buffer */ | |
388 | |
389 /* do the real write-out */ | |
390 for (cur = *list; cur; cur = cur->next) { | |
391 i += aimutil_put16(buf+i, cur->tlv->type); | |
392 i += aimutil_put16(buf+i, cur->tlv->length); | |
393 memcpy(buf+i, cur->tlv->value, cur->tlv->length); | |
394 i += cur->tlv->length; | |
395 } | |
396 | |
397 return i; | |
398 } | |
399 | |
400 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
401 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
402 * aim_gettlv - Grab the Nth TLV of type type in the TLV list list. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
403 * @list: Source chain |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
404 * @type: Requested TLV type |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
405 * @nth: Index of TLV of type to get |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
406 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
407 * Returns a pointer to an aim_tlv_t of the specified type; |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
408 * %NULL on error. The @nth parameter is specified starting at %1. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
409 * In most cases, there will be no more than one TLV of any type |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
410 * in a chain. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
411 * |
237 | 412 */ |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
413 faim_export struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *list, u_short type, int nth) |
237 | 414 { |
415 int i; | |
416 struct aim_tlvlist_t *cur; | |
417 | |
418 i = 0; | |
419 for (cur = list; cur != NULL; cur = cur->next) | |
420 { | |
421 if (cur && cur->tlv) | |
422 { | |
423 if (cur->tlv->type == type) | |
424 i++; | |
425 if (i >= nth) | |
426 return cur->tlv; | |
427 } | |
428 } | |
429 return NULL; | |
430 } | |
431 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
432 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
433 * aim_gettlv_str - Retrieve the Nth TLV in chain as a string. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
434 * @list: Source TLV chain |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
435 * @type: TLV type to search for |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
436 * @nth: Index of TLV to return |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
437 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
438 * Same as aim_gettlv(), except that the return value is a %NULL- |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
439 * terminated string instead of an aim_tlv_t. This is a |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
440 * dynamic buffer and must be freed by the caller. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
441 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
442 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
443 faim_export char *aim_gettlv_str(struct aim_tlvlist_t *list, u_short type, int nth) |
237 | 444 { |
445 struct aim_tlv_t *tlv; | |
446 char *newstr; | |
447 | |
448 if (!(tlv = aim_gettlv(list, type, nth))) | |
449 return NULL; | |
450 | |
451 newstr = (char *) malloc(tlv->length + 1); | |
452 memcpy(newstr, tlv->value, tlv->length); | |
453 *(newstr + tlv->length) = '\0'; | |
454 | |
455 return newstr; | |
456 } | |
457 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
458 /** |
1245
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
459 * aim_gettlv8 - Retrieve the Nth TLV in chain as a 8bit integer. |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
460 * @list: Source TLV chain |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
461 * @type: TLV type to search for |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
462 * @nth: Index of TLV to return |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
463 * |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
464 * Same as aim_gettlv(), except that the return value is a |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
465 * 8bit integer instead of an aim_tlv_t. |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
466 * |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
467 */ |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
468 faim_internal unsigned char aim_gettlv8(struct aim_tlvlist_t *list, unsigned short type, int num) |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
469 { |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
470 struct aim_tlv_t *tlv; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
471 |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
472 if (!(tlv = aim_gettlv(list, type, num)) || !tlv->value) |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
473 return 0; /* erm */ |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
474 return aimutil_get8(tlv->value); |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
475 } |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
476 |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
477 /** |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
478 * aim_gettlv16 - Retrieve the Nth TLV in chain as a 16bit integer. |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
479 * @list: Source TLV chain |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
480 * @type: TLV type to search for |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
481 * @nth: Index of TLV to return |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
482 * |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
483 * Same as aim_gettlv(), except that the return value is a |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
484 * 16bit integer instead of an aim_tlv_t. |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
485 * |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
486 */ |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
487 faim_internal unsigned short aim_gettlv16(struct aim_tlvlist_t *list, unsigned short type, int num) |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
488 { |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
489 struct aim_tlv_t *tlv; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
490 |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
491 if (!(tlv = aim_gettlv(list, type, num)) || !tlv->value) |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
492 return 0; /* erm */ |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
493 return aimutil_get16(tlv->value); |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
494 } |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
495 |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
496 /** |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
497 * aim_gettlv32 - Retrieve the Nth TLV in chain as a 32bit integer. |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
498 * @list: Source TLV chain |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
499 * @type: TLV type to search for |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
500 * @nth: Index of TLV to return |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
501 * |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
502 * Same as aim_gettlv(), except that the return value is a |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
503 * 32bit integer instead of an aim_tlv_t. |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
504 * |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
505 */ |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
506 faim_internal unsigned long aim_gettlv32(struct aim_tlvlist_t *list, unsigned short type, int num) |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
507 { |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
508 struct aim_tlv_t *tlv; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
509 |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
510 if (!(tlv = aim_gettlv(list, type, num)) || !tlv->value) |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
511 return 0; /* erm */ |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
512 return aimutil_get32(tlv->value); |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
513 } |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
514 |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
515 /** |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
516 * aim_grabtlv - Grab a single TLV from a data buffer |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
517 * @src: Source data buffer (must be at least 4 bytes long) |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
518 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
519 * Creates a TLV structure aim_tlv_t and returns it |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
520 * filled with values from a buffer, possibly including a |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
521 * dynamically allocated buffer for the value portion. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
522 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
523 * Both the aim_tlv_t and the tlv->value pointer |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
524 * must be freed by the caller if non-%NULL. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
525 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
526 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
527 faim_export struct aim_tlv_t *aim_grabtlv(u_char *src) |
2 | 528 { |
529 struct aim_tlv_t *dest = NULL; | |
530 | |
531 dest = aim_createtlv(); | |
532 | |
533 dest->type = src[0] << 8; | |
534 dest->type += src[1]; | |
535 | |
536 dest->length = src[2] << 8; | |
537 dest->length += src[3]; | |
538 | |
539 dest->value = (u_char *) malloc(dest->length*sizeof(u_char)); | |
540 memset(dest->value, 0, dest->length*sizeof(u_char)); | |
541 | |
542 memcpy(dest->value, &(src[4]), dest->length*sizeof(u_char)); | |
543 | |
544 return dest; | |
545 } | |
546 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
547 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
548 * aim_grabtlvstr - Grab a single TLV from a data buffer as string |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
549 * @src: Source data buffer (must be at least 4 bytes long) |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
550 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
551 * Creates a TLV structure aim_tlv_t and returns it |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
552 * filled with values from a buffer, possibly including a |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
553 * dynamically allocated buffer for the value portion, which |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
554 * is %NULL-terminated as a string. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
555 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
556 * Both the aim_tlv_t and the tlv->value pointer |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
557 * must be freed by the caller if non-%NULL. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
558 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
559 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
560 faim_export struct aim_tlv_t *aim_grabtlvstr(u_char *src) |
2 | 561 { |
562 struct aim_tlv_t *dest = NULL; | |
563 | |
564 dest = aim_createtlv(); | |
565 | |
566 dest->type = src[0] << 8; | |
567 dest->type += src[1]; | |
568 | |
569 dest->length = src[2] << 8; | |
570 dest->length += src[3]; | |
571 | |
572 dest->value = (u_char *) malloc((dest->length+1)*sizeof(u_char)); | |
573 memset(dest->value, 0, (dest->length+1)*sizeof(u_char)); | |
574 | |
575 memcpy(dest->value, &(src[4]), dest->length*sizeof(u_char)); | |
576 dest->value[dest->length] = '\0'; | |
577 | |
578 return dest; | |
579 } | |
580 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
581 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
582 * aim_puttlv - Write a aim_tlv_t into a data buffer |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
583 * @dest: Destination data buffer |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
584 * @newtlv: Source TLV structure |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
585 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
586 * Writes out the passed TLV structure into the buffer. No bounds |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
587 * checking is done on the output buffer. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
588 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
589 * The passed aim_tlv_t is not freed. aim_freetlv() should |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
590 * still be called by the caller to free the structure. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
591 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
592 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
593 faim_export int aim_puttlv(u_char *dest, struct aim_tlv_t *newtlv) |
2 | 594 { |
595 int i=0; | |
596 | |
597 dest[i++] = newtlv->type >> 8; | |
598 dest[i++] = newtlv->type & 0x00FF; | |
599 dest[i++] = newtlv->length >> 8; | |
600 dest[i++] = newtlv->length & 0x00FF; | |
601 memcpy(&(dest[i]), newtlv->value, newtlv->length); | |
602 i+=newtlv->length; | |
603 return i; | |
604 } | |
605 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
606 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
607 * aim_createtlv - Generate an aim_tlv_t structure. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
608 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
609 * Allocates an empty TLV structure and returns a pointer |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
610 * to it; %NULL on error. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
611 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
612 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
613 faim_export struct aim_tlv_t *aim_createtlv(void) |
2 | 614 { |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
615 struct aim_tlv_t *newtlv; |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
616 |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
617 if (!(newtlv = (struct aim_tlv_t *)malloc(sizeof(struct aim_tlv_t)))) |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
618 return NULL; |
2 | 619 memset(newtlv, 0, sizeof(struct aim_tlv_t)); |
620 return newtlv; | |
621 } | |
622 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
623 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
624 * aim_freetlv - Free a aim_tlv_t structure |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
625 * @oldtlv: TLV to be destroyed |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
626 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
627 * Frees both the TLV structure and the value portion. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
628 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
629 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
630 faim_export int aim_freetlv(struct aim_tlv_t **oldtlv) |
2 | 631 { |
632 if (!oldtlv) | |
633 return -1; | |
634 if (!*oldtlv) | |
635 return -1; | |
636 if ((*oldtlv)->value) | |
637 free((*oldtlv)->value); | |
638 free(*(oldtlv)); | |
639 (*oldtlv) = NULL; | |
640 | |
641 return 0; | |
642 } | |
643 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
644 /** |
1245
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
645 * aim_puttlv_8 - Write a one-byte TLV. |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
646 * @buf: Destination buffer |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
647 * @t: TLV type |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
648 * @v: Value |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
649 * |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
650 * Writes a TLV with a one-byte integer value portion. |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
651 * |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
652 */ |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
653 faim_export int aim_puttlv_8(unsigned char *buf, unsigned short t, unsigned char v) |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
654 { |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
655 int curbyte=0; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
656 |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
657 curbyte += aimutil_put16(buf+curbyte, (unsigned short)(t&0xffff)); |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
658 curbyte += aimutil_put16(buf+curbyte, (unsigned short)0x0001); |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
659 curbyte += aimutil_put8(buf+curbyte, (unsigned char)(v&0xff)); |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
660 |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
661 return curbyte; |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
662 } |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
663 |
2ac6ccb94229
[gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1081
diff
changeset
|
664 /** |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
665 * aim_puttlv_16 - Write a two-byte TLV. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
666 * @buf: Destination buffer |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
667 * @t: TLV type |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
668 * @v: Value |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
669 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
670 * Writes a TLV with a two-byte integer value portion. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
671 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
672 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
673 faim_export int aim_puttlv_16(u_char *buf, u_short t, u_short v) |
2 | 674 { |
675 int curbyte=0; | |
237 | 676 curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff)); |
677 curbyte += aimutil_put16(buf+curbyte, (u_short)0x0002); | |
678 curbyte += aimutil_put16(buf+curbyte, (u_short)(v&0xffff)); | |
679 return curbyte; | |
680 } | |
681 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
682 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
683 * aim_puttlv_32 - Write a four-byte TLV. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
684 * @buf: Destination buffer |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
685 * @t: TLV type |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
686 * @v: Value |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
687 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
688 * Writes a TLV with a four-byte integer value portion. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
689 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
690 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
691 faim_export int aim_puttlv_32(u_char *buf, u_short t, u_long v) |
237 | 692 { |
693 int curbyte=0; | |
694 curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff)); | |
695 curbyte += aimutil_put16(buf+curbyte, (u_short)0x0004); | |
696 curbyte += aimutil_put32(buf+curbyte, (u_long)(v&0xffffffff)); | |
2 | 697 return curbyte; |
698 } | |
237 | 699 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
700 /** |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
701 * aim_puttlv_str - Write a string TLV. |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
702 * @buf: Destination buffer |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
703 * @t: TLV type |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
704 * @l: Length of string |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
705 * @v: String to write |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
706 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
707 * Writes a TLV with a string value portion. (Only the first @l |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
708 * bytes of the passed string will be written, which should not |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
709 * include the terminating NULL.) |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
710 * |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
711 */ |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
712 faim_export int aim_puttlv_str(u_char *buf, u_short t, int l, char *v) |
237 | 713 { |
714 int curbyte; | |
715 | |
716 curbyte = 0; | |
717 curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff)); | |
718 curbyte += aimutil_put16(buf+curbyte, (u_short)(l&0xffff)); | |
719 if (v) | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
818
diff
changeset
|
720 memcpy(buf+curbyte, (unsigned char *)v, l); |
237 | 721 curbyte += l; |
722 return curbyte; | |
723 } |