| 1 |
|
| /* vim:set ft=c ts=2 sw=2 sts=2 et cindent: */ |
| 2 |
|
| /* |
| 3 |
|
| * ***** BEGIN LICENSE BLOCK ***** |
| 4 |
|
| * Version: MIT |
| 5 |
|
| * |
| 6 |
|
| * Portions created by Alan Antonuk are Copyright (c) 2012-2013 |
| 7 |
|
| * Alan Antonuk. All Rights Reserved. |
| 8 |
|
| * |
| 9 |
|
| * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. |
| 10 |
|
| * All Rights Reserved. |
| 11 |
|
| * |
| 12 |
|
| * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 |
| 13 |
|
| * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. |
| 14 |
|
| * |
| 15 |
|
| * Permission is hereby granted, free of charge, to any person |
| 16 |
|
| * obtaining a copy of this software and associated documentation |
| 17 |
|
| * files (the "Software"), to deal in the Software without |
| 18 |
|
| * restriction, including without limitation the rights to use, copy, |
| 19 |
|
| * modify, merge, publish, distribute, sublicense, and/or sell copies |
| 20 |
|
| * of the Software, and to permit persons to whom the Software is |
| 21 |
|
| * furnished to do so, subject to the following conditions: |
| 22 |
|
| * |
| 23 |
|
| * The above copyright notice and this permission notice shall be |
| 24 |
|
| * included in all copies or substantial portions of the Software. |
| 25 |
|
| * |
| 26 |
|
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 27 |
|
| * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 28 |
|
| * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 29 |
|
| * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 30 |
|
| * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 31 |
|
| * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 32 |
|
| * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 33 |
|
| * SOFTWARE. |
| 34 |
|
| * ***** END LICENSE BLOCK ***** |
| 35 |
|
| */ |
| 36 |
|
| |
| 37 |
|
| #ifdef HAVE_CONFIG_H |
| 38 |
|
| #include "config.h" |
| 39 |
|
| #endif |
| 40 |
|
| |
| 41 |
|
| #include "amqp_private.h" |
| 42 |
|
| #include "amqp_table.h" |
| 43 |
|
| #include <assert.h> |
| 44 |
|
| #include <stdint.h> |
| 45 |
|
| #include <stdio.h> |
| 46 |
|
| #include <stdlib.h> |
| 47 |
|
| #include <string.h> |
| 48 |
|
| |
| 49 |
|
| #define INITIAL_ARRAY_SIZE 16 |
| 50 |
|
| #define INITIAL_TABLE_SIZE 16 |
| 51 |
|
| |
| 52 |
|
| static int amqp_decode_field_value(amqp_bytes_t encoded, |
| 53 |
|
| amqp_pool_t *pool, |
| 54 |
|
| amqp_field_value_t *entry, |
| 55 |
|
| size_t *offset); |
| 56 |
|
| |
| 57 |
|
| static int amqp_encode_field_value(amqp_bytes_t encoded, |
| 58 |
|
| amqp_field_value_t *entry, |
| 59 |
|
| size_t *offset); |
| 60 |
|
| |
| 61 |
|
| /*---------------------------------------------------------------------------*/ |
| 62 |
|
| |
| 63 |
0 |
| static int amqp_decode_array(amqp_bytes_t encoded, |
| 64 |
|
| amqp_pool_t *pool, |
| 65 |
|
| amqp_array_t *output, |
| 66 |
|
| size_t *offset) |
| 67 |
|
| { |
| 68 |
|
| uint32_t arraysize; |
| 69 |
0 |
| int num_entries = 0; |
| 70 |
0 |
| int allocated_entries = INITIAL_ARRAY_SIZE; |
| 71 |
|
| amqp_field_value_t *entries; |
| 72 |
|
| size_t limit; |
| 73 |
|
| int res; |
| 74 |
|
| |
| 75 |
0 |
▶ | if (!amqp_decode_32(encoded, offset, &arraysize)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!amqp_decode_32(encoded, offset, &arraysize)) { |
0 |
0 |
0 |
|
| 76 |
0 |
| return AMQP_STATUS_BAD_AMQP_DATA; |
| 77 |
|
| } |
| 78 |
|
| |
| 79 |
0 |
| entries = malloc(allocated_entries * sizeof(amqp_field_value_t)); |
| 80 |
0 |
▶ | if (entries == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (entries == NULL) { |
0 |
0 |
0 |
|
| 81 |
0 |
| return AMQP_STATUS_NO_MEMORY; |
| 82 |
|
| } |
| 83 |
|
| |
| 84 |
0 |
| limit = *offset + arraysize; |
| 85 |
0 |
▶ | while (*offset < limit) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (*offset < limit) { |
0 |
0 |
0 |
|
| 86 |
0 |
▶ | if (num_entries >= allocated_entries) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (num_entries >= allocated_entries) { |
0 |
0 |
0 |
|
| 87 |
|
| void *newentries; |
| 88 |
0 |
| allocated_entries = allocated_entries * 2; |
| 89 |
0 |
| newentries = realloc(entries, allocated_entries * sizeof(amqp_field_value_t)); |
| 90 |
0 |
| res = AMQP_STATUS_NO_MEMORY; |
| 91 |
0 |
▶ | if (newentries == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (newentries == NULL) { |
0 |
0 |
0 |
|
| 92 |
0 |
| goto out; |
| 93 |
|
| } |
| 94 |
|
| |
| 95 |
0 |
| entries = newentries; |
| 96 |
|
| } |
| 97 |
|
| |
| 98 |
0 |
| res = amqp_decode_field_value(encoded, pool, &entries[num_entries], |
| 99 |
|
| offset); |
| 100 |
0 |
▶ | if (res < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (res < 0) { |
0 |
0 |
0 |
|
| 101 |
0 |
| goto out; |
| 102 |
|
| } |
| 103 |
|
| |
| 104 |
0 |
| num_entries++; |
| 105 |
|
| } |
| 106 |
|
| |
| 107 |
0 |
| output->num_entries = num_entries; |
| 108 |
0 |
| output->entries = amqp_pool_alloc(pool, num_entries * sizeof(amqp_field_value_t)); |
| 109 |
0 |
| res = AMQP_STATUS_NO_MEMORY; |
| 110 |
|
| /* NULL is legitimate if we requested a zero-length block. */ |
| 111 |
0 |
▶ | if (output->entries == NULL && num_entries > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (output->entries == NULL && num_entries > 0) { |
0 |
0 |
0 |
| if (output->entries == NULL && num_entries > 0) { |
0 |
0 |
0 |
|
| 112 |
0 |
| goto out; |
| 113 |
|
| } |
| 114 |
|
| |
| 115 |
0 |
| memcpy(output->entries, entries, num_entries * sizeof(amqp_field_value_t)); |
| 116 |
0 |
| res = 0; |
| 117 |
|
| |
| 118 |
0 |
| out: |
| 119 |
0 |
| free(entries); |
| 120 |
0 |
| return res; |
| 121 |
|
| } |
| 122 |
|
| |
| 123 |
0 |
| int amqp_decode_table(amqp_bytes_t encoded, |
| 124 |
|
| amqp_pool_t *pool, |
| 125 |
|
| amqp_table_t *output, |
| 126 |
|
| size_t *offset) |
| 127 |
|
| { |
| 128 |
|
| uint32_t tablesize; |
| 129 |
0 |
| int num_entries = 0; |
| 130 |
|
| amqp_table_entry_t *entries; |
| 131 |
0 |
| int allocated_entries = INITIAL_TABLE_SIZE; |
| 132 |
|
| size_t limit; |
| 133 |
|
| int res; |
| 134 |
|
| |
| 135 |
0 |
▶ | if (!amqp_decode_32(encoded, offset, &tablesize)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!amqp_decode_32(encoded, offset, &tablesize)) { |
0 |
0 |
0 |
|
| 136 |
0 |
| return AMQP_STATUS_BAD_AMQP_DATA; |
| 137 |
|
| } |
| 138 |
|
| |
| 139 |
0 |
| entries = malloc(allocated_entries * sizeof(amqp_table_entry_t)); |
| 140 |
0 |
▶ | if (entries == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (entries == NULL) { |
0 |
0 |
0 |
|
| 141 |
0 |
| return AMQP_STATUS_NO_MEMORY; |
| 142 |
|
| } |
| 143 |
|
| |
| 144 |
0 |
| limit = *offset + tablesize; |
| 145 |
0 |
▶ | while (*offset < limit) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (*offset < limit) { |
0 |
0 |
0 |
|
| 146 |
|
| uint8_t keylen; |
| 147 |
|
| |
| 148 |
0 |
| res = AMQP_STATUS_BAD_AMQP_DATA; |
| 149 |
0 |
▶ | if (!amqp_decode_8(encoded, offset, &keylen)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!amqp_decode_8(encoded, offset, &keylen)) { |
0 |
0 |
0 |
|
| 150 |
0 |
| goto out; |
| 151 |
|
| } |
| 152 |
|
| |
| 153 |
0 |
▶ | if (num_entries >= allocated_entries) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (num_entries >= allocated_entries) { |
0 |
0 |
0 |
|
| 154 |
|
| void *newentries; |
| 155 |
0 |
| allocated_entries = allocated_entries * 2; |
| 156 |
0 |
| newentries = realloc(entries, allocated_entries * sizeof(amqp_table_entry_t)); |
| 157 |
0 |
| res = AMQP_STATUS_NO_MEMORY; |
| 158 |
0 |
▶ | if (newentries == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (newentries == NULL) { |
0 |
0 |
0 |
|
| 159 |
0 |
| goto out; |
| 160 |
|
| } |
| 161 |
|
| |
| 162 |
0 |
| entries = newentries; |
| 163 |
|
| } |
| 164 |
|
| |
| 165 |
0 |
| res = AMQP_STATUS_BAD_AMQP_DATA; |
| 166 |
0 |
▶ | if (!amqp_decode_bytes(encoded, offset, &entries[num_entries].key, keylen)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!amqp_decode_bytes(encoded, offset, &entries[num_entries].key, keylen)) { |
0 |
0 |
0 |
|
| 167 |
0 |
| goto out; |
| 168 |
|
| } |
| 169 |
|
| |
| 170 |
0 |
| res = amqp_decode_field_value(encoded, pool, &entries[num_entries].value, |
| 171 |
|
| offset); |
| 172 |
0 |
▶ | if (res < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (res < 0) { |
0 |
0 |
0 |
|
| 173 |
0 |
| goto out; |
| 174 |
|
| } |
| 175 |
|
| |
| 176 |
0 |
| num_entries++; |
| 177 |
|
| } |
| 178 |
|
| |
| 179 |
0 |
| output->num_entries = num_entries; |
| 180 |
0 |
| output->entries = amqp_pool_alloc(pool, num_entries * sizeof(amqp_table_entry_t)); |
| 181 |
0 |
| res = AMQP_STATUS_NO_MEMORY; |
| 182 |
|
| /* NULL is legitimate if we requested a zero-length block. */ |
| 183 |
0 |
▶ | if (output->entries == NULL && num_entries > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (output->entries == NULL && num_entries > 0) { |
0 |
0 |
0 |
| if (output->entries == NULL && num_entries > 0) { |
0 |
0 |
0 |
|
| 184 |
0 |
| goto out; |
| 185 |
|
| } |
| 186 |
|
| |
| 187 |
0 |
| memcpy(output->entries, entries, num_entries * sizeof(amqp_table_entry_t)); |
| 188 |
0 |
| res = AMQP_STATUS_OK; |
| 189 |
|
| |
| 190 |
0 |
| out: |
| 191 |
0 |
| free(entries); |
| 192 |
0 |
| return res; |
| 193 |
|
| } |
| 194 |
|
| |
| 195 |
0 |
| static int amqp_decode_field_value(amqp_bytes_t encoded, |
| 196 |
|
| amqp_pool_t *pool, |
| 197 |
|
| amqp_field_value_t *entry, |
| 198 |
|
| size_t *offset) |
| 199 |
|
| { |
| 200 |
0 |
| int res = AMQP_STATUS_BAD_AMQP_DATA; |
| 201 |
|
| |
| 202 |
0 |
▶ | if (!amqp_decode_8(encoded, offset, &entry->kind)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!amqp_decode_8(encoded, offset, &entry->kind)) { |
0 |
0 |
0 |
|
| 203 |
0 |
| goto out; |
| 204 |
|
| } |
| 205 |
|
| |
| 206 |
|
| #define TRIVIAL_FIELD_DECODER(bits) if (!amqp_decode_##bits(encoded, offset, &entry->value.u##bits)) goto out; break |
| 207 |
|
| #define SIMPLE_FIELD_DECODER(bits, dest, how) { uint##bits##_t val; if (!amqp_decode_##bits(encoded, offset, &val)) goto out; entry->value.dest = how; } break |
| 208 |
|
| |
| 209 |
0 |
| switch (entry->kind) { |
| 210 |
0 |
| case AMQP_FIELD_KIND_BOOLEAN: |
| 211 |
0 |
▶ | SIMPLE_FIELD_DECODER(8, boolean, val ? 1 : 0); |
Branch: 1 branch
| Branch | True | False | Total |
| SIMPLE_FIELD_DECODER(8, boolean, val ? 1 : 0); |
0 |
0 |
0 |
|
| 212 |
|
| |
| 213 |
0 |
| case AMQP_FIELD_KIND_I8: |
| 214 |
0 |
▶ | SIMPLE_FIELD_DECODER(8, i8, (int8_t)val); |
Branch: 1 branch
| Branch | True | False | Total |
| SIMPLE_FIELD_DECODER(8, i8, (int8_t)val); |
0 |
0 |
0 |
|
| 215 |
0 |
| case AMQP_FIELD_KIND_U8: |
| 216 |
0 |
▶ | TRIVIAL_FIELD_DECODER(8); |
Branch: 1 branch
| Branch | True | False | Total |
| TRIVIAL_FIELD_DECODER(8); |
0 |
0 |
0 |
|
| 217 |
|
| |
| 218 |
0 |
| case AMQP_FIELD_KIND_I16: |
| 219 |
0 |
▶ | SIMPLE_FIELD_DECODER(16, i16, (int16_t)val); |
Branch: 1 branch
| Branch | True | False | Total |
| SIMPLE_FIELD_DECODER(16, i16, (int16_t)val); |
0 |
0 |
0 |
|
| 220 |
0 |
| case AMQP_FIELD_KIND_U16: |
| 221 |
0 |
▶ | TRIVIAL_FIELD_DECODER(16); |
Branch: 1 branch
| Branch | True | False | Total |
| TRIVIAL_FIELD_DECODER(16); |
0 |
0 |
0 |
|
| 222 |
|
| |
| 223 |
0 |
| case AMQP_FIELD_KIND_I32: |
| 224 |
0 |
▶ | SIMPLE_FIELD_DECODER(32, i32, (int32_t)val); |
Branch: 1 branch
| Branch | True | False | Total |
| SIMPLE_FIELD_DECODER(32, i32, (int32_t)val); |
0 |
0 |
0 |
|
| 225 |
0 |
| case AMQP_FIELD_KIND_U32: |
| 226 |
0 |
▶ | TRIVIAL_FIELD_DECODER(32); |
Branch: 1 branch
| Branch | True | False | Total |
| TRIVIAL_FIELD_DECODER(32); |
0 |
0 |
0 |
|
| 227 |
|
| |
| 228 |
0 |
| case AMQP_FIELD_KIND_I64: |
| 229 |
0 |
▶ | SIMPLE_FIELD_DECODER(64, i64, (int64_t)val); |
Branch: 1 branch
| Branch | True | False | Total |
| SIMPLE_FIELD_DECODER(64, i64, (int64_t)val); |
0 |
0 |
0 |
|
| 230 |
0 |
| case AMQP_FIELD_KIND_U64: |
| 231 |
0 |
▶ | TRIVIAL_FIELD_DECODER(64); |
Branch: 1 branch
| Branch | True | False | Total |
| TRIVIAL_FIELD_DECODER(64); |
0 |
0 |
0 |
|
| 232 |
|
| |
| 233 |
0 |
| case AMQP_FIELD_KIND_F32: |
| 234 |
0 |
▶ | TRIVIAL_FIELD_DECODER(32); |
Branch: 1 branch
| Branch | True | False | Total |
| TRIVIAL_FIELD_DECODER(32); |
0 |
0 |
0 |
|
| 235 |
|
| /* and by punning, f32 magically gets the right value...! */ |
| 236 |
|
| |
| 237 |
0 |
| case AMQP_FIELD_KIND_F64: |
| 238 |
0 |
▶ | TRIVIAL_FIELD_DECODER(64); |
Branch: 1 branch
| Branch | True | False | Total |
| TRIVIAL_FIELD_DECODER(64); |
0 |
0 |
0 |
|
| 239 |
|
| /* and by punning, f64 magically gets the right value...! */ |
| 240 |
|
| |
| 241 |
0 |
| case AMQP_FIELD_KIND_DECIMAL: |
| 242 |
0 |
▶ | if (!amqp_decode_8(encoded, offset, &entry->value.decimal.decimals) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!amqp_decode_8(encoded, offset, &entry->value.decimal.decimals) |
0 |
0 |
0 |
|
| 243 |
0 |
▶ | || !amqp_decode_32(encoded, offset, &entry->value.decimal.value)) { |
Branch: 1 branch
| Branch | True | False | Total |
| || !amqp_decode_32(encoded, offset, &entry->value.decimal.value)) { |
0 |
0 |
0 |
|
| 244 |
0 |
| goto out; |
| 245 |
|
| } |
| 246 |
0 |
| break; |
| 247 |
|
| |
| 248 |
0 |
| case AMQP_FIELD_KIND_UTF8: |
| 249 |
|
| /* AMQP_FIELD_KIND_UTF8 and AMQP_FIELD_KIND_BYTES have the |
| 250 |
|
| same implementation, but different interpretations. */ |
| 251 |
|
| /* fall through */ |
| 252 |
|
| case AMQP_FIELD_KIND_BYTES: { |
| 253 |
|
| uint32_t len; |
| 254 |
0 |
▶ | if (!amqp_decode_32(encoded, offset, &len) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!amqp_decode_32(encoded, offset, &len) |
0 |
0 |
0 |
|
| 255 |
0 |
▶ | || !amqp_decode_bytes(encoded, offset, &entry->value.bytes, len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| || !amqp_decode_bytes(encoded, offset, &entry->value.bytes, len)) { |
0 |
0 |
0 |
|
| 256 |
0 |
| goto out; |
| 257 |
|
| } |
| 258 |
0 |
| break; |
| 259 |
|
| } |
| 260 |
|
| |
| 261 |
0 |
| case AMQP_FIELD_KIND_ARRAY: |
| 262 |
0 |
| res = amqp_decode_array(encoded, pool, &(entry->value.array), offset); |
| 263 |
0 |
| goto out; |
| 264 |
|
| |
| 265 |
0 |
| case AMQP_FIELD_KIND_TIMESTAMP: |
| 266 |
0 |
▶ | TRIVIAL_FIELD_DECODER(64); |
Branch: 1 branch
| Branch | True | False | Total |
| TRIVIAL_FIELD_DECODER(64); |
0 |
0 |
0 |
|
| 267 |
|
| |
| 268 |
0 |
| case AMQP_FIELD_KIND_TABLE: |
| 269 |
0 |
| res = amqp_decode_table(encoded, pool, &(entry->value.table), offset); |
| 270 |
0 |
| goto out; |
| 271 |
|
| |
| 272 |
0 |
| case AMQP_FIELD_KIND_VOID: |
| 273 |
0 |
| break; |
| 274 |
|
| |
| 275 |
0 |
| default: |
| 276 |
0 |
| goto out; |
| 277 |
|
| } |
| 278 |
|
| |
| 279 |
0 |
| res = AMQP_STATUS_OK; |
| 280 |
|
| |
| 281 |
0 |
| out: |
| 282 |
0 |
| return res; |
| 283 |
|
| } |
| 284 |
|
| |
| 285 |
|
| /*---------------------------------------------------------------------------*/ |
| 286 |
|
| |
| 287 |
0 |
| static int amqp_encode_array(amqp_bytes_t encoded, |
| 288 |
|
| amqp_array_t *input, |
| 289 |
|
| size_t *offset) |
| 290 |
|
| { |
| 291 |
0 |
| size_t start = *offset; |
| 292 |
|
| int i, res; |
| 293 |
|
| |
| 294 |
0 |
| *offset += 4; /* size of the array gets filled in later on */ |
| 295 |
|
| |
| 296 |
0 |
▶ | for (i = 0; i < input->num_entries; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < input->num_entries; i++) { |
0 |
0 |
0 |
|
| 297 |
0 |
| res = amqp_encode_field_value(encoded, &input->entries[i], offset); |
| 298 |
0 |
▶ | if (res < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (res < 0) { |
0 |
0 |
0 |
|
| 299 |
0 |
| goto out; |
| 300 |
|
| } |
| 301 |
|
| } |
| 302 |
|
| |
| 303 |
0 |
▶ | if (!amqp_encode_32(encoded, &start, (uint32_t)(*offset - start - 4))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!amqp_encode_32(encoded, &start, (uint32_t)(*offset - start - 4))) { |
0 |
0 |
0 |
|
| 304 |
0 |
| res = AMQP_STATUS_TABLE_TOO_BIG; |
| 305 |
0 |
| goto out; |
| 306 |
|
| } |
| 307 |
|
| |
| 308 |
0 |
| res = AMQP_STATUS_OK; |
| 309 |
|
| |
| 310 |
0 |
| out: |
| 311 |
0 |
| return res; |
| 312 |
|
| } |
| 313 |
|
| |
| 314 |
0 |
| int amqp_encode_table(amqp_bytes_t encoded, |
| 315 |
|
| amqp_table_t *input, |
| 316 |
|
| size_t *offset) |
| 317 |
|
| { |
| 318 |
0 |
| size_t start = *offset; |
| 319 |
|
| int i, res; |
| 320 |
|
| |
| 321 |
0 |
| *offset += 4; /* size of the table gets filled in later on */ |
| 322 |
|
| |
| 323 |
0 |
▶ | for (i = 0; i < input->num_entries; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < input->num_entries; i++) { |
0 |
0 |
0 |
|
| 324 |
0 |
▶ | if (!amqp_encode_8(encoded, offset, (uint8_t)input->entries[i].key.len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!amqp_encode_8(encoded, offset, (uint8_t)input->entries[i].key.len)) { |
0 |
0 |
0 |
|
| 325 |
0 |
| res = AMQP_STATUS_TABLE_TOO_BIG; |
| 326 |
0 |
| goto out; |
| 327 |
|
| } |
| 328 |
|
| |
| 329 |
0 |
▶ | if (!amqp_encode_bytes(encoded, offset, input->entries[i].key)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!amqp_encode_bytes(encoded, offset, input->entries[i].key)) { |
0 |
0 |
0 |
|
| 330 |
0 |
| res = AMQP_STATUS_TABLE_TOO_BIG; |
| 331 |
0 |
| goto out; |
| 332 |
|
| } |
| 333 |
|
| |
| 334 |
0 |
| res = amqp_encode_field_value(encoded, &input->entries[i].value, offset); |
| 335 |
0 |
▶ | if (res < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (res < 0) { |
0 |
0 |
0 |
|
| 336 |
0 |
| goto out; |
| 337 |
|
| } |
| 338 |
|
| } |
| 339 |
|
| |
| 340 |
0 |
▶ | if (!amqp_encode_32(encoded, &start, (uint32_t)(*offset - start - 4))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!amqp_encode_32(encoded, &start, (uint32_t)(*offset - start - 4))) { |
0 |
0 |
0 |
|
| 341 |
0 |
| res = AMQP_STATUS_TABLE_TOO_BIG; |
| 342 |
0 |
| goto out; |
| 343 |
|
| } |
| 344 |
|
| |
| 345 |
0 |
| res = AMQP_STATUS_OK; |
| 346 |
|
| |
| 347 |
0 |
| out: |
| 348 |
0 |
| return res; |
| 349 |
|
| } |
| 350 |
|
| |
| 351 |
0 |
| static int amqp_encode_field_value(amqp_bytes_t encoded, |
| 352 |
|
| amqp_field_value_t *entry, |
| 353 |
|
| size_t *offset) |
| 354 |
|
| { |
| 355 |
0 |
| int res = AMQP_STATUS_BAD_AMQP_DATA; |
| 356 |
|
| |
| 357 |
0 |
▶ | if (!amqp_encode_8(encoded, offset, entry->kind)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!amqp_encode_8(encoded, offset, entry->kind)) { |
0 |
0 |
0 |
|
| 358 |
0 |
| goto out; |
| 359 |
|
| } |
| 360 |
|
| |
| 361 |
|
| #define FIELD_ENCODER(bits, val) if (!amqp_encode_##bits(encoded, offset, val)) { \ |
| 362 |
|
| res = AMQP_STATUS_TABLE_TOO_BIG; \ |
| 363 |
|
| goto out; \ |
| 364 |
|
| } \ |
| 365 |
|
| break |
| 366 |
|
| |
| 367 |
0 |
| switch (entry->kind) { |
| 368 |
0 |
| case AMQP_FIELD_KIND_BOOLEAN: |
| 369 |
0 |
▶ | FIELD_ENCODER(8, entry->value.boolean ? 1 : 0); |
Branch: 1 branch
| Branch | True | False | Total |
| FIELD_ENCODER(8, entry->value.boolean ? 1 : 0); |
0 |
0 |
0 |
|
| 370 |
|
| |
| 371 |
0 |
| case AMQP_FIELD_KIND_I8: |
| 372 |
0 |
▶ | FIELD_ENCODER(8, entry->value.i8); |
Branch: 1 branch
| Branch | True | False | Total |
| FIELD_ENCODER(8, entry->value.i8); |
0 |
0 |
0 |
|
| 373 |
0 |
| case AMQP_FIELD_KIND_U8: |
| 374 |
0 |
▶ | FIELD_ENCODER(8, entry->value.u8); |
Branch: 1 branch
| Branch | True | False | Total |
| FIELD_ENCODER(8, entry->value.u8); |
0 |
0 |
0 |
|
| 375 |
|
| |
| 376 |
0 |
| case AMQP_FIELD_KIND_I16: |
| 377 |
0 |
▶ | FIELD_ENCODER(16, entry->value.i16); |
Branch: 1 branch
| Branch | True | False | Total |
| FIELD_ENCODER(16, entry->value.i16); |
0 |
0 |
0 |
|
| 378 |
0 |
| case AMQP_FIELD_KIND_U16: |
| 379 |
0 |
▶ | FIELD_ENCODER(16, entry->value.u16); |
Branch: 1 branch
| Branch | True | False | Total |
| FIELD_ENCODER(16, entry->value.u16); |
0 |
0 |
0 |
|
| 380 |
|
| |
| 381 |
0 |
| case AMQP_FIELD_KIND_I32: |
| 382 |
0 |
▶ | FIELD_ENCODER(32, entry->value.i32); |
Branch: 1 branch
| Branch | True | False | Total |
| FIELD_ENCODER(32, entry->value.i32); |
0 |
0 |
0 |
|
| 383 |
0 |
| case AMQP_FIELD_KIND_U32: |
| 384 |
0 |
▶ | FIELD_ENCODER(32, entry->value.u32); |
Branch: 1 branch
| Branch | True | False | Total |
| FIELD_ENCODER(32, entry->value.u32); |
0 |
0 |
0 |
|
| 385 |
|
| |
| 386 |
0 |
| case AMQP_FIELD_KIND_I64: |
| 387 |
0 |
▶ | FIELD_ENCODER(64, entry->value.i64); |
Branch: 1 branch
| Branch | True | False | Total |
| FIELD_ENCODER(64, entry->value.i64); |
0 |
0 |
0 |
|
| 388 |
0 |
| case AMQP_FIELD_KIND_U64: |
| 389 |
0 |
▶ | FIELD_ENCODER(64, entry->value.u64); |
Branch: 1 branch
| Branch | True | False | Total |
| FIELD_ENCODER(64, entry->value.u64); |
0 |
0 |
0 |
|
| 390 |
|
| |
| 391 |
0 |
| case AMQP_FIELD_KIND_F32: |
| 392 |
|
| /* by punning, u32 magically gets the right value...! */ |
| 393 |
0 |
▶ | FIELD_ENCODER(32, entry->value.u32); |
Branch: 1 branch
| Branch | True | False | Total |
| FIELD_ENCODER(32, entry->value.u32); |
0 |
0 |
0 |
|
| 394 |
|
| |
| 395 |
0 |
| case AMQP_FIELD_KIND_F64: |
| 396 |
|
| /* by punning, u64 magically gets the right value...! */ |
| 397 |
0 |
▶ | FIELD_ENCODER(64, entry->value.u64); |
Branch: 1 branch
| Branch | True | False | Total |
| FIELD_ENCODER(64, entry->value.u64); |
0 |
0 |
0 |
|
| 398 |
|
| |
| 399 |
0 |
| case AMQP_FIELD_KIND_DECIMAL: |
| 400 |
0 |
▶ | if (!amqp_encode_8(encoded, offset, entry->value.decimal.decimals) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!amqp_encode_8(encoded, offset, entry->value.decimal.decimals) |
0 |
0 |
0 |
|
| 401 |
0 |
▶ | || !amqp_encode_32(encoded, offset, entry->value.decimal.value)) { |
Branch: 1 branch
| Branch | True | False | Total |
| || !amqp_encode_32(encoded, offset, entry->value.decimal.value)) { |
0 |
0 |
0 |
|
| 402 |
0 |
| res = AMQP_STATUS_TABLE_TOO_BIG; |
| 403 |
0 |
| goto out; |
| 404 |
|
| } |
| 405 |
0 |
| break; |
| 406 |
|
| |
| 407 |
0 |
| case AMQP_FIELD_KIND_UTF8: |
| 408 |
|
| /* AMQP_FIELD_KIND_UTF8 and AMQP_FIELD_KIND_BYTES have the |
| 409 |
|
| same implementation, but different interpretations. */ |
| 410 |
|
| /* fall through */ |
| 411 |
|
| case AMQP_FIELD_KIND_BYTES: |
| 412 |
0 |
▶ | if (!amqp_encode_32(encoded, offset, (uint32_t)entry->value.bytes.len) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!amqp_encode_32(encoded, offset, (uint32_t)entry->value.bytes.len) |
0 |
0 |
0 |
|
| 413 |
0 |
▶ | || !amqp_encode_bytes(encoded, offset, entry->value.bytes)) { |
Branch: 1 branch
| Branch | True | False | Total |
| || !amqp_encode_bytes(encoded, offset, entry->value.bytes)) { |
0 |
0 |
0 |
|
| 414 |
0 |
| res = AMQP_STATUS_TABLE_TOO_BIG; |
| 415 |
0 |
| goto out; |
| 416 |
|
| } |
| 417 |
0 |
| break; |
| 418 |
|
| |
| 419 |
0 |
| case AMQP_FIELD_KIND_ARRAY: |
| 420 |
0 |
| res = amqp_encode_array(encoded, &entry->value.array, offset); |
| 421 |
0 |
| goto out; |
| 422 |
|
| |
| 423 |
0 |
| case AMQP_FIELD_KIND_TIMESTAMP: |
| 424 |
0 |
▶ | FIELD_ENCODER(64, entry->value.u64); |
Branch: 1 branch
| Branch | True | False | Total |
| FIELD_ENCODER(64, entry->value.u64); |
0 |
0 |
0 |
|
| 425 |
|
| |
| 426 |
0 |
| case AMQP_FIELD_KIND_TABLE: |
| 427 |
0 |
| res = amqp_encode_table(encoded, &entry->value.table, offset); |
| 428 |
0 |
| goto out; |
| 429 |
|
| |
| 430 |
0 |
| case AMQP_FIELD_KIND_VOID: |
| 431 |
0 |
| break; |
| 432 |
|
| |
| 433 |
0 |
| default: |
| 434 |
0 |
| res = AMQP_STATUS_INVALID_PARAMETER; |
| 435 |
0 |
| goto out; |
| 436 |
|
| } |
| 437 |
|
| |
| 438 |
0 |
| res = AMQP_STATUS_OK; |
| 439 |
|
| |
| 440 |
0 |
| out: |
| 441 |
0 |
| return res; |
| 442 |
|
| } |
| 443 |
|
| |
| 444 |
|
| /*---------------------------------------------------------------------------*/ |
| 445 |
|
| |
| 446 |
0 |
| int amqp_table_entry_cmp(void const *entry1, void const *entry2) |
| 447 |
|
| { |
| 448 |
0 |
| amqp_table_entry_t const *p1 = (amqp_table_entry_t const *) entry1; |
| 449 |
0 |
| amqp_table_entry_t const *p2 = (amqp_table_entry_t const *) entry2; |
| 450 |
|
| |
| 451 |
|
| int d; |
| 452 |
|
| size_t minlen; |
| 453 |
|
| |
| 454 |
0 |
| minlen = p1->key.len; |
| 455 |
0 |
▶ | if (p2->key.len < minlen) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p2->key.len < minlen) { |
0 |
0 |
0 |
|
| 456 |
0 |
| minlen = p2->key.len; |
| 457 |
|
| } |
| 458 |
|
| |
| 459 |
0 |
| d = memcmp(p1->key.bytes, p2->key.bytes, minlen); |
| 460 |
0 |
▶ | if (d != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (d != 0) { |
0 |
0 |
0 |
|
| 461 |
0 |
| return d; |
| 462 |
|
| } |
| 463 |
|
| |
| 464 |
0 |
| return (int)p1->key.len - (int)p2->key.len; |
| 465 |
|
| } |
| 466 |
|
| |
| 467 |
|
| static int |
| 468 |
0 |
| amqp_field_value_clone(const amqp_field_value_t *original, amqp_field_value_t *clone, amqp_pool_t *pool) |
| 469 |
|
| { |
| 470 |
|
| int i; |
| 471 |
|
| int res; |
| 472 |
0 |
| clone->kind = original->kind; |
| 473 |
|
| |
| 474 |
0 |
| switch (clone->kind) { |
| 475 |
0 |
| case AMQP_FIELD_KIND_BOOLEAN: |
| 476 |
0 |
| clone->value.boolean = original->value.boolean; |
| 477 |
0 |
| break; |
| 478 |
|
| |
| 479 |
0 |
| case AMQP_FIELD_KIND_I8: |
| 480 |
0 |
| clone->value.i8 = original->value.i8; |
| 481 |
0 |
| break; |
| 482 |
|
| |
| 483 |
0 |
| case AMQP_FIELD_KIND_U8: |
| 484 |
0 |
| clone->value.u8 = original->value.u8; |
| 485 |
0 |
| break; |
| 486 |
|
| |
| 487 |
0 |
| case AMQP_FIELD_KIND_I16: |
| 488 |
0 |
| clone->value.i16 = original->value.i16; |
| 489 |
0 |
| break; |
| 490 |
|
| |
| 491 |
0 |
| case AMQP_FIELD_KIND_U16: |
| 492 |
0 |
| clone->value.u16 = original->value.u16; |
| 493 |
0 |
| break; |
| 494 |
|
| |
| 495 |
0 |
| case AMQP_FIELD_KIND_I32: |
| 496 |
0 |
| clone->value.i32 = original->value.i32; |
| 497 |
0 |
| break; |
| 498 |
|
| |
| 499 |
0 |
| case AMQP_FIELD_KIND_U32: |
| 500 |
0 |
| clone->value.u32 = original->value.u32; |
| 501 |
0 |
| break; |
| 502 |
|
| |
| 503 |
0 |
| case AMQP_FIELD_KIND_I64: |
| 504 |
0 |
| clone->value.i64 = original->value.i64; |
| 505 |
0 |
| break; |
| 506 |
|
| |
| 507 |
0 |
| case AMQP_FIELD_KIND_U64: |
| 508 |
|
| case AMQP_FIELD_KIND_TIMESTAMP: |
| 509 |
0 |
| clone->value.u64 = original->value.u64; |
| 510 |
0 |
| break; |
| 511 |
|
| |
| 512 |
0 |
| case AMQP_FIELD_KIND_F32: |
| 513 |
0 |
| clone->value.f32 = original->value.f32; |
| 514 |
0 |
| break; |
| 515 |
|
| |
| 516 |
0 |
| case AMQP_FIELD_KIND_F64: |
| 517 |
0 |
| clone->value.f64 = original->value.f64; |
| 518 |
0 |
| break; |
| 519 |
|
| |
| 520 |
0 |
| case AMQP_FIELD_KIND_DECIMAL: |
| 521 |
0 |
| clone->value.decimal = original->value.decimal; |
| 522 |
0 |
| break; |
| 523 |
|
| |
| 524 |
0 |
| case AMQP_FIELD_KIND_UTF8: |
| 525 |
|
| case AMQP_FIELD_KIND_BYTES: |
| 526 |
0 |
▶ | if (0 == original->value.bytes.len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (0 == original->value.bytes.len) { |
0 |
0 |
0 |
|
| 527 |
0 |
| clone->value.bytes = amqp_empty_bytes; |
| 528 |
|
| } else { |
| 529 |
0 |
| amqp_pool_alloc_bytes(pool, original->value.bytes.len, &clone->value.bytes); |
| 530 |
0 |
▶ | if (NULL == clone->value.bytes.bytes) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL == clone->value.bytes.bytes) { |
0 |
0 |
0 |
|
| 531 |
0 |
| return AMQP_STATUS_NO_MEMORY; |
| 532 |
|
| } |
| 533 |
0 |
| memcpy(clone->value.bytes.bytes, original->value.bytes.bytes, clone->value.bytes.len); |
| 534 |
|
| } |
| 535 |
0 |
| break; |
| 536 |
|
| |
| 537 |
0 |
| case AMQP_FIELD_KIND_ARRAY: |
| 538 |
0 |
▶ | if (0 == original->value.array.entries) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (0 == original->value.array.entries) { |
0 |
0 |
0 |
|
| 539 |
0 |
| clone->value.array = amqp_empty_array; |
| 540 |
|
| } else { |
| 541 |
0 |
| clone->value.array.num_entries = original->value.array.num_entries; |
| 542 |
0 |
| clone->value.array.entries = amqp_pool_alloc(pool, clone->value.array.num_entries * sizeof(amqp_field_value_t)); |
| 543 |
0 |
▶ | if (NULL == clone->value.array.entries) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL == clone->value.array.entries) { |
0 |
0 |
0 |
|
| 544 |
0 |
| return AMQP_STATUS_NO_MEMORY; |
| 545 |
|
| } |
| 546 |
|
| |
| 547 |
0 |
▶ | for (i = 0; i < clone->value.array.num_entries; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < clone->value.array.num_entries; ++i) { |
0 |
0 |
0 |
|
| 548 |
0 |
| res = amqp_field_value_clone(&original->value.array.entries[i], &clone->value.array.entries[i], pool); |
| 549 |
0 |
▶ | if (AMQP_STATUS_OK != res) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (AMQP_STATUS_OK != res) { |
0 |
0 |
0 |
|
| 550 |
0 |
| return res; |
| 551 |
|
| } |
| 552 |
|
| } |
| 553 |
|
| } |
| 554 |
0 |
| break; |
| 555 |
|
| |
| 556 |
0 |
| case AMQP_FIELD_KIND_TABLE: |
| 557 |
0 |
| return amqp_table_clone(&original->value.table, &clone->value.table, pool); |
| 558 |
|
| |
| 559 |
0 |
| case AMQP_FIELD_KIND_VOID: |
| 560 |
0 |
| break; |
| 561 |
|
| |
| 562 |
0 |
| default: |
| 563 |
0 |
| return AMQP_STATUS_INVALID_PARAMETER; |
| 564 |
|
| } |
| 565 |
|
| |
| 566 |
0 |
| return AMQP_STATUS_OK; |
| 567 |
|
| } |
| 568 |
|
| |
| 569 |
|
| |
| 570 |
|
| static int |
| 571 |
0 |
| amqp_table_entry_clone(const amqp_table_entry_t *original, amqp_table_entry_t *clone, amqp_pool_t *pool) |
| 572 |
|
| { |
| 573 |
0 |
▶ | if (0 == original->key.len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (0 == original->key.len) { |
0 |
0 |
0 |
|
| 574 |
0 |
| return AMQP_STATUS_INVALID_PARAMETER; |
| 575 |
|
| } |
| 576 |
|
| |
| 577 |
0 |
| amqp_pool_alloc_bytes(pool, original->key.len, &clone->key); |
| 578 |
0 |
▶ | if (NULL == clone->key.bytes) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL == clone->key.bytes) { |
0 |
0 |
0 |
|
| 579 |
0 |
| return AMQP_STATUS_NO_MEMORY; |
| 580 |
|
| } |
| 581 |
|
| |
| 582 |
0 |
| memcpy(clone->key.bytes, original->key.bytes, clone->key.len); |
| 583 |
|
| |
| 584 |
0 |
| return amqp_field_value_clone(&original->value, &clone->value, pool); |
| 585 |
|
| } |
| 586 |
|
| |
| 587 |
|
| int |
| 588 |
0 |
| amqp_table_clone(const amqp_table_t *original, amqp_table_t *clone, amqp_pool_t *pool) |
| 589 |
|
| { |
| 590 |
|
| int i; |
| 591 |
|
| int res; |
| 592 |
0 |
| clone->num_entries = original->num_entries; |
| 593 |
0 |
▶ | if (0 == clone->num_entries) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (0 == clone->num_entries) { |
0 |
0 |
0 |
|
| 594 |
0 |
| *clone = amqp_empty_table; |
| 595 |
0 |
| return AMQP_STATUS_OK; |
| 596 |
|
| } |
| 597 |
|
| |
| 598 |
0 |
| clone->entries = amqp_pool_alloc(pool, clone->num_entries * sizeof(amqp_table_entry_t)); |
| 599 |
|
| |
| 600 |
0 |
▶ | if (NULL == clone->entries) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL == clone->entries) { |
0 |
0 |
0 |
|
| 601 |
0 |
| return AMQP_STATUS_NO_MEMORY; |
| 602 |
|
| } |
| 603 |
|
| |
| 604 |
0 |
▶ | for (i = 0; i < clone->num_entries; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < clone->num_entries; ++i) { |
0 |
0 |
0 |
|
| 605 |
0 |
| res = amqp_table_entry_clone(&original->entries[i], &clone->entries[i], pool); |
| 606 |
0 |
▶ | if (AMQP_STATUS_OK != res) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (AMQP_STATUS_OK != res) { |
0 |
0 |
0 |
|
| 607 |
0 |
| goto error_out1; |
| 608 |
|
| } |
| 609 |
|
| } |
| 610 |
|
| |
| 611 |
0 |
| return AMQP_STATUS_OK; |
| 612 |
|
| |
| 613 |
0 |
| error_out1: |
| 614 |
0 |
| return res; |
| 615 |
|
| } |
| 616 |
|
| |
| 617 |
0 |
| amqp_table_entry_t amqp_table_construct_utf8_entry(const char *key, |
| 618 |
|
| const char *value) { |
| 619 |
|
| amqp_table_entry_t ret; |
| 620 |
0 |
| ret.key = amqp_cstring_bytes(key); |
| 621 |
0 |
| ret.value.kind = AMQP_FIELD_KIND_UTF8; |
| 622 |
0 |
| ret.value.value.bytes = amqp_cstring_bytes(value); |
| 623 |
0 |
| return ret; |
| 624 |
|
| } |
| 625 |
|
| |
| 626 |
0 |
| amqp_table_entry_t amqp_table_construct_table_entry(const char *key, |
| 627 |
|
| const amqp_table_t *value) { |
| 628 |
|
| amqp_table_entry_t ret; |
| 629 |
0 |
| ret.key = amqp_cstring_bytes(key); |
| 630 |
0 |
| ret.value.kind = AMQP_FIELD_KIND_TABLE; |
| 631 |
0 |
| ret.value.value.table = *value; |
| 632 |
0 |
| return ret; |
| 633 |
|
| } |
| 634 |
|
| |
| 635 |
0 |
| amqp_table_entry_t amqp_table_construct_bool_entry(const char *key, |
| 636 |
|
| const int value) { |
| 637 |
|
| amqp_table_entry_t ret; |
| 638 |
0 |
| ret.key = amqp_cstring_bytes(key); |
| 639 |
0 |
| ret.value.kind = AMQP_FIELD_KIND_BOOLEAN; |
| 640 |
0 |
| ret.value.value.boolean = value; |
| 641 |
0 |
| return ret; |
| 642 |
|
| } |
| 643 |
|
| |
| 644 |
0 |
| amqp_table_entry_t *amqp_table_get_entry_by_key(const amqp_table_t *table, |
| 645 |
|
| const amqp_bytes_t key) { |
| 646 |
|
| int i; |
| 647 |
0 |
▶ | assert(table != NULL); |
Branch: 1 branch
| Branch | True | False | Total |
| assert(table != NULL); |
0 |
0 |
0 |
|
| 648 |
0 |
▶ | for (i = 0; i < table->num_entries; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < table->num_entries; ++i) { |
0 |
0 |
0 |
|
| 649 |
0 |
▶ | if (amqp_bytes_equal(table->entries[i].key, key)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (amqp_bytes_equal(table->entries[i].key, key)) { |
0 |
0 |
0 |
|
| 650 |
0 |
| return &table->entries[i]; |
| 651 |
|
| } |
| 652 |
|
| } |
| 653 |
0 |
| return NULL; |
| 654 |
|
| } |