comparison src/protocols/oscar/tlv.c @ 4317:7c9f3d0fe8b2

[gaim-migrate @ 4571] Eh, nothing really. Very minor clean up stuff. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 16 Jan 2003 00:49:15 +0000
parents 9f729d6d88a6
children 858979ab3867
comparison
equal deleted inserted replaced
4316:c5851f0e120e 4317:7c9f3d0fe8b2
113 * @param num The max number of TLVs that will be read, or -1 if unlimited. 113 * @param num The max number of TLVs that will be read, or -1 if unlimited.
114 * There are a number of places where you want to read in a tlvchain, 114 * There are a number of places where you want to read in a tlvchain,
115 * but the chain is not at the end of the SNAC, and the chain is 115 * but the chain is not at the end of the SNAC, and the chain is
116 * preceeded by the number of TLVs. So you can limit that with this. 116 * preceeded by the number of TLVs. So you can limit that with this.
117 * 117 *
118 * AAA - Change this. It would never need to read in unlimited, right?
119 * That's what aim_readtlvchain() is for. Dumb ass.
120 *
121 * Reads and parses a series of TLV patterns from a data buffer; the 118 * Reads and parses a series of TLV patterns from a data buffer; the
122 * returned structure is manipulatable with the rest of the TLV 119 * returned structure is manipulatable with the rest of the TLV
123 * routines. When done with a TLV chain, aim_freetlvchain() should 120 * routines. When done with a TLV chain, aim_freetlvchain() should
124 * be called to free the dynamic substructures. 121 * be called to free the dynamic substructures.
125 * 122 *
131 * 128 *
132 */ 129 */
133 faim_internal aim_tlvlist_t *aim_readtlvchain_num(aim_bstream_t *bs, fu16_t num) 130 faim_internal aim_tlvlist_t *aim_readtlvchain_num(aim_bstream_t *bs, fu16_t num)
134 { 131 {
135 aim_tlvlist_t *list = NULL, *cur; 132 aim_tlvlist_t *list = NULL, *cur;
136 133
137 while ((aim_bstream_empty(bs) > 0) && (num != 0)) { 134 while ((aim_bstream_empty(bs) > 0) && (num != 0)) {
138 fu16_t type, length; 135 fu16_t type, length;
139 136
140 type = aimbs_get16(bs); 137 type = aimbs_get16(bs);
141 length = aimbs_get16(bs); 138 length = aimbs_get16(bs);
159 aim_freetlvchain(&list); 156 aim_freetlvchain(&list);
160 return NULL; 157 return NULL;
161 } 158 }
162 cur->tlv->type = type; 159 cur->tlv->type = type;
163 if ((cur->tlv->length = length)) { 160 if ((cur->tlv->length = length)) {
164 cur->tlv->value = aimbs_getraw(bs, length); 161 cur->tlv->value = aimbs_getraw(bs, length);
165 if (!cur->tlv->value) { 162 if (!cur->tlv->value) {
166 freetlv(&cur->tlv); 163 freetlv(&cur->tlv);
167 free(cur); 164 free(cur);
168 aim_freetlvchain(&list); 165 aim_freetlvchain(&list);
169 return NULL; 166 return NULL;
177 174
178 return list; 175 return list;
179 } 176 }
180 177
181 /** 178 /**
182 * aim_readtlvchain_num - Read a TLV chain from a buffer. 179 * aim_readtlvchain_len - Read a TLV chain from a buffer.
183 * @param bs Input bstream 180 * @param bs Input bstream
184 * @param len The max length in bytes that will be read. 181 * @param len The max length in bytes that will be read.
185 * There are a number of places where you want to read in a tlvchain, 182 * There are a number of places where you want to read in a tlvchain,
186 * but the chain is not at the end of the SNAC, and the chain is 183 * but the chain is not at the end of the SNAC, and the chain is
187 * preceeded by the length of the TLVs. So you can limit that with this. 184 * preceeded by the length of the TLVs. So you can limit that with this.
199 * 196 *
200 */ 197 */
201 faim_internal aim_tlvlist_t *aim_readtlvchain_len(aim_bstream_t *bs, fu16_t len) 198 faim_internal aim_tlvlist_t *aim_readtlvchain_len(aim_bstream_t *bs, fu16_t len)
202 { 199 {
203 aim_tlvlist_t *list = NULL, *cur; 200 aim_tlvlist_t *list = NULL, *cur;
204 201
205 while ((aim_bstream_empty(bs) > 0) && (len > 0)) { 202 while ((aim_bstream_empty(bs) > 0) && (len > 0)) {
206 fu16_t type, length; 203 fu16_t type, length;
207 204
208 type = aimbs_get16(bs); 205 type = aimbs_get16(bs);
209 length = aimbs_get16(bs); 206 length = aimbs_get16(bs);
227 aim_freetlvchain(&list); 224 aim_freetlvchain(&list);
228 return NULL; 225 return NULL;
229 } 226 }
230 cur->tlv->type = type; 227 cur->tlv->type = type;
231 if ((cur->tlv->length = length)) { 228 if ((cur->tlv->length = length)) {
232 cur->tlv->value = aimbs_getraw(bs, length); 229 cur->tlv->value = aimbs_getraw(bs, length);
233 if (!cur->tlv->value) { 230 if (!cur->tlv->value) {
234 freetlv(&cur->tlv); 231 freetlv(&cur->tlv);
235 free(cur); 232 free(cur);
236 aim_freetlvchain(&list); 233 aim_freetlvchain(&list);
237 return NULL; 234 return NULL;