Changeset 862371b for libfaim/tlv.c
- Timestamp:
- Jun 29, 2003, 1:47:04 PM (22 years ago)
- Branches:
- master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- e016fc2
- Parents:
- 03ad7b2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfaim/tlv.c
r5e53c4a r862371b 29 29 /** 30 30 * aim_readtlvchain - Read a TLV chain from a buffer. 31 * @buf: Input buffer 32 * @maxlen: Length of input buffer 31 * @param bs Input bstream 33 32 * 34 33 * Reads and parses a series of TLV patterns from a data buffer; the … … 47 46 { 48 47 aim_tlvlist_t *list = NULL, *cur; 49 48 50 49 while (aim_bstream_empty(bs) > 0) { 51 50 fu16_t type, length; … … 71 70 else { 72 71 73 if (length > aim_bstream_empty(bs)) 74 goto errout; 72 if (length > aim_bstream_empty(bs)) { 73 aim_freetlvchain(&list); 74 return NULL; 75 } 75 76 76 77 cur = (aim_tlvlist_t *)malloc(sizeof(aim_tlvlist_t)); 77 if (!cur) 78 goto errout; 78 if (!cur) { 79 aim_freetlvchain(&list); 80 return NULL; 81 } 79 82 80 83 memset(cur, 0, sizeof(aim_tlvlist_t)); 81 84 82 cur->tlv = createtlv(); 85 cur->tlv = createtlv(); 83 86 if (!cur->tlv) { 84 87 free(cur); 85 goto errout; 88 aim_freetlvchain(&list); 89 return NULL; 86 90 } 87 91 cur->tlv->type = type; … … 91 95 freetlv(&cur->tlv); 92 96 free(cur); 93 goto errout; 97 aim_freetlvchain(&list); 98 return NULL; 94 99 } 95 100 } … … 101 106 102 107 return list; 103 104 errout: 105 aim_freetlvchain(&list); 106 return NULL; 108 } 109 110 /** 111 * aim_readtlvchain_num - Read a TLV chain from a buffer. 112 * @param bs Input bstream 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, 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. 117 * 118 * Reads and parses a series of TLV patterns from a data buffer; the 119 * returned structure is manipulatable with the rest of the TLV 120 * routines. When done with a TLV chain, aim_freetlvchain() should 121 * be called to free the dynamic substructures. 122 * 123 * XXX There should be a flag setable here to have the tlvlist contain 124 * bstream references, so that at least the ->value portion of each 125 * element doesn't need to be malloc/memcpy'd. This could prove to be 126 * just as effecient as the in-place TLV parsing used in a couple places 127 * in libfaim. 128 * 129 */ 130 faim_internal aim_tlvlist_t *aim_readtlvchain_num(aim_bstream_t *bs, fu16_t num) 131 { 132 aim_tlvlist_t *list = NULL, *cur; 133 134 while ((aim_bstream_empty(bs) > 0) && (num != 0)) { 135 fu16_t type, length; 136 137 type = aimbs_get16(bs); 138 length = aimbs_get16(bs); 139 140 if (length > aim_bstream_empty(bs)) { 141 aim_freetlvchain(&list); 142 return NULL; 143 } 144 145 cur = (aim_tlvlist_t *)malloc(sizeof(aim_tlvlist_t)); 146 if (!cur) { 147 aim_freetlvchain(&list); 148 return NULL; 149 } 150 151 memset(cur, 0, sizeof(aim_tlvlist_t)); 152 153 cur->tlv = createtlv(); 154 if (!cur->tlv) { 155 free(cur); 156 aim_freetlvchain(&list); 157 return NULL; 158 } 159 cur->tlv->type = type; 160 if ((cur->tlv->length = length)) { 161 cur->tlv->value = aimbs_getraw(bs, length); 162 if (!cur->tlv->value) { 163 freetlv(&cur->tlv); 164 free(cur); 165 aim_freetlvchain(&list); 166 return NULL; 167 } 168 } 169 170 num--; 171 cur->next = list; 172 list = cur; 173 } 174 175 return list; 107 176 } 108 177 … … 182 251 183 252 /** 184 * aim_addtlvtochain_ str- Add a string to a TLV chain253 * aim_addtlvtochain_raw - Add a string to a TLV chain 185 254 * @list: Desination chain (%NULL pointer if empty) 186 * @t ype: TLV type187 * @ str: String to add188 * @ len: Length of string to add (not including %NULL)255 * @t: TLV type 256 * @l: Length of string to add (not including %NULL) 257 * @v: String to add 189 258 * 190 259 * Adds the passed string as a TLV element of the passed type … … 245 314 * aim_addtlvtochain16 - Add a 16bit integer to a TLV chain 246 315 * @list: Destination chain 247 * @t ype: TLV type to add248 * @v al: Value to add316 * @t: TLV type to add 317 * @v: Value to add 249 318 * 250 319 * Adds a two-byte unsigned integer to a TLV chain. … … 607 676 } 608 677 #endif 609
Note: See TracChangeset
for help on using the changeset viewer.