* pops an str from the current position in the packet * @info: pointer to store the result * * @return: * 0 (success): info retrieved * 1 (success): nothing returned, all data has been consumed! * < 0: error * * Note: The pointer returned in @info str is only valid for the duration of * the callback. Don't forget to copy the info into a safe buffer! */
| 330 | * the callback. Don't forget to copy the info into a safe buffer! |
| 331 | */ |
| 332 | int bin_pop_str(bin_packet_t *packet, str *info) |
| 333 | { |
| 334 | if (packet->front_pointer - packet->buffer.s == packet->buffer.len) |
| 335 | return 1; |
| 336 | |
| 337 | if (packet->front_pointer - packet->buffer.s > packet->buffer.len || |
| 338 | packet->front_pointer - packet->buffer.s + LEN_FIELD_SIZE > packet->buffer.len) |
| 339 | goto error; |
| 340 | |
| 341 | info->len = 0; |
| 342 | memcpy(&info->len, packet->front_pointer, LEN_FIELD_SIZE); |
| 343 | packet->front_pointer += LEN_FIELD_SIZE; |
| 344 | |
| 345 | if (packet->front_pointer - packet->buffer.s + info->len > packet->buffer.len) |
| 346 | goto error; |
| 347 | |
| 348 | if (info->len == 0) |
| 349 | info->s = NULL; |
| 350 | else |
| 351 | info->s = packet->front_pointer; |
| 352 | |
| 353 | packet->front_pointer += info->len; |
| 354 | |
| 355 | LM_DBG("Popped: '%.*s' [%d]\n", info->len, info->s, info->len); |
| 356 | |
| 357 | return 0; |
| 358 | |
| 359 | error: |
| 360 | LM_ERR("Receive binary packet buffer overflow\n"); |
| 361 | return -1; |
| 362 | } |
| 363 | |
| 364 | /* |
| 365 | * pops an integer value from the current position in the buffer |
no outgoing calls
no test coverage detected