unbound: sldns/sbuffer.c File Reference

unbound 0.1

Functions
sbuffer.c File Reference

This file contains the definition of sldns_buffer, and functions to manipulate those. More...

`#include "config.h"`
`#include "sldns/sbuffer.h"`
`#include <stdarg.h>`

## Functions
sldns_buffer * | sldns_buffer_new (size_t capacity)
| creates a new buffer with the specified capacity.
void | sldns_buffer_new_frm_data (sldns_buffer *buffer, void *data, size_t size)
| creates a buffer with the specified data.
void | sldns_buffer_init_frm_data (sldns_buffer *buffer, void *data, size_t size)
| Setup a buffer with the data pointed to.
int | sldns_buffer_set_capacity (sldns_buffer *buffer, size_t capacity)
| changes the buffer's capacity.
int | sldns_buffer_reserve (sldns_buffer *buffer, size_t amount)
| ensures BUFFER can contain at least AMOUNT more bytes.
int | sldns_buffer_printf (sldns_buffer *buffer, const char *format,...)
void | sldns_buffer_free (sldns_buffer *buffer)
| frees the buffer.
void | sldns_buffer_copy (sldns_buffer *result, sldns_buffer *from)
| Copy contents of the from buffer to the result buffer and then flips the result buffer.

## Detailed Description

This file contains the definition of sldns_buffer, and functions to manipulate those.

## Function Documentation

## ◆ sldns_buffer_new()

sldns_buffer * sldns_buffer_new | ( | size_t | capacity | ) |

creates a new buffer with the specified capacity.

Parameters

  [in] | capacity | the size (in bytes) to allocate for the buffer

Returns
  the created buffer

References sldns_buffer::_capacity, sldns_buffer::_data, sldns_buffer::_fixed, sldns_buffer::_limit, sldns_buffer::_position, and sldns_buffer::_status_err.

Referenced by anchors_apply_cfg(), anchors_test(), answer_callback_from_entry(), check_mod(), comm_point_create_http_out(), comm_point_create_local(), comm_point_create_tcp_handler(), comm_point_create_tcp_out(), comm_point_tcp_handle_callback(), dname_test(), dstest_file(), fake_front_query(), fake_pending_callback(), hex_buffer2wire(), libworker_setup(), listen_create(), log_dns_msg(), main(), mesh_create(), msgparse_test(), msgtostr(), nsec3_hash_test(), outside_network_create(), pending_tcp_query(), pending_udp_query(), process_answer_detail(), read_entry(), send_em(), service(), verifytest_file(), worker_init(), zonemd_check_test(), zonemd_generate_test(), zonemd_offline_verify(), and zonemd_verify_test().

## ◆ sldns_buffer_new_frm_data()

void sldns_buffer_new_frm_data | ( | sldns_buffer * | buffer,
|  | void * | data,
|  | size_t | size )

creates a buffer with the specified data.

The data IS copied and MEMORY allocations are done. The buffer is not fixed and can be resized using buffer_reserve().

Parameters

  [in] | buffer | pointer to the buffer to put the data in
  [in] | data | the data to encapsulate in the buffer
  [in] | size | the size of the data

References sldns_buffer::_capacity, sldns_buffer::_data, sldns_buffer::_fixed, sldns_buffer::_limit, sldns_buffer::_position, and sldns_buffer::_status_err.

Referenced by hex_buffer2wire().

## ◆ sldns_buffer_init_frm_data()

void sldns_buffer_init_frm_data | ( | sldns_buffer * | buffer,
|  | void * | data,
|  | size_t | size )

Setup a buffer with the data pointed to.

No data copied, no memory allocs. The buffer is fixed.

Parameters

  [in] | buffer | pointer to the buffer to put the data in
  [in] | data | the data to encapsulate in the buffer
  [in] | size | the size of the data

References sldns_buffer::_capacity, sldns_buffer::_data, sldns_buffer::_fixed, and sldns_buffer::_limit.

Referenced by chunk_rrlist_get_current(), decompress_rr_into_buffer(), log_rrlist_position(), pending_tcp_query(), sldns_str2wire_ipseckey_buf(), sldns_str2wire_nsec_buf(), sldns_str2wire_wks_buf(), and use_free_buffer().

## ◆ sldns_buffer_set_capacity()

int sldns_buffer_set_capacity | ( | sldns_buffer * | buffer,
|  | size_t | capacity )

changes the buffer's capacity.

The data is reallocated so any pointers to the data may become invalid. The buffer's limit is set to the buffer's new capacity.

Parameters

  [in] | buffer | the buffer
  [in] | capacity | the capacity to use

Returns
  whether this failed or succeeded

References sldns_buffer::_capacity, sldns_buffer::_data, sldns_buffer::_fixed, sldns_buffer::_limit, sldns_buffer::_position, and sldns_buffer::_status_err.

Referenced by sldns_buffer_reserve().

## ◆ sldns_buffer_reserve()

int sldns_buffer_reserve | ( | sldns_buffer * | buffer,
|  | size_t | amount )

ensures BUFFER can contain at least AMOUNT more bytes.

The buffer's capacity is increased if necessary using buffer_set_capacity().

The buffer's limit is always set to the (possibly increased) capacity.

Parameters

  [in] | buffer | the buffer
  [in] | amount | amount to use

Returns
  whether this failed or succeeded

References sldns_buffer::_capacity, sldns_buffer::_fixed, sldns_buffer::_limit, sldns_buffer::_position, sldns_buffer::_status_err, and sldns_buffer_set_capacity().

## ◆ sldns_buffer_free()

void sldns_buffer_free | ( | sldns_buffer * | buffer | ) |

frees the buffer.

Parameters

  [in] | *buffer | the buffer to be freed

References sldns_buffer::_data, and sldns_buffer::_fixed.

Referenced by anchors_apply_cfg(), anchors_test(), answer_callback_from_entry(), check_mod(), comm_point_create_http_out(), comm_point_create_tcp_handler(), comm_point_create_tcp_out(), comm_point_delete(), comm_point_drop_reply(), delete_fake_pending(), delete_replay_answer(), delete_replylist(), dname_test(), dstest_file(), fake_pending_callback(), libworker_delete_env(), libworker_setup(), listen_delete(), listen_delete(), log_dns_msg(), main(), mesh_delete(), msgparse_test(), msgtostr(), nsec3_hash_test(), outnet_serviced_query_stop(), outside_network_delete(), process_answer_detail(), read_entry(), send_em(), service(), verifytest_file(), worker_delete(), zonemd_check_test(), zonemd_generate_test(), zonemd_offline_verify(), and zonemd_verify_test().

## ◆ sldns_buffer_copy()

void sldns_buffer_copy | ( | sldns_buffer * | result,
|  | sldns_buffer * | from )

Copy contents of the from buffer to the result buffer and then flips the result buffer.

Data will be silently truncated if the result buffer is too small.

Parameters

  [out] | *result | resulting buffer which is copied to.
  [in] | *from | what to copy to result.

References sldns_buffer_begin(), sldns_buffer_capacity(), sldns_buffer_clear(), sldns_buffer_flip(), sldns_buffer_limit(), and sldns_buffer_write().

Referenced by entry_to_buf(), mesh_make_new_space(), mesh_send_reply(), outnet_comm_point_for_tcp(), and reply_and_prefetch().