17 #include "plugins_internal.h"
21 # include <winsock2.h>
22 # include <ws2tcpip.h>
24 # include <arpa/inet.h>
25 # if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__)
26 # include <netinet/in.h>
27 # include <sys/socket.h>
39 #include "ly_common.h"
52 uint32_t *fixed_size_bits)
55 *fixed_size_bits = 32;
62 lyplg_type_store_ipv4_address_no_zone(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value,
63 uint32_t value_size_bits, uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
72 memset(storage, 0,
sizeof *storage);
74 LY_CHECK_ERR_GOTO(!val, ret =
LY_EMEM, cleanup);
80 LY_CHECK_GOTO(ret, cleanup);
84 memcpy(&val->
addr, value, 4);
92 LY_CHECK_GOTO(ret, cleanup);
96 value = strndup(value, value_size);
97 LY_CHECK_ERR_GOTO(!value, ret =
LY_EMEM, cleanup);
103 if (!inet_pton(AF_INET, value, &val->
addr)) {
110 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
111 LY_CHECK_GOTO(ret, cleanup);
114 if (options & LYPLG_TYPE_STORE_DYNAMIC) {
128 lyplg_type_compare_ipv4_address_no_zone(
const struct ly_ctx *UNUSED(ctx),
const struct lyd_value *val1,
146 lyplg_type_sort_ipv4_address_no_zone(
const struct ly_ctx *UNUSED(ctx),
const struct lyd_value *val1,
162 void *UNUSED(prefix_data),
ly_bool *dynamic, uint32_t *value_size_bits)
171 if (value_size_bits) {
172 *value_size_bits = 32;
179 ret = malloc(INET_ADDRSTRLEN);
180 LY_CHECK_RET(!ret, NULL);
183 if (!inet_ntop(AF_INET, &val->
addr, ret, INET_ADDRSTRLEN)) {
185 LOGERR(ctx,
LY_ESYS,
"Failed to get IPv4 address in string (%s).", strerror(errno));
200 if (value_size_bits) {
201 *value_size_bits = strlen(value->
_canonical) * 8;
215 .
module =
"ietf-inet-types",
216 .revision =
"2013-07-15",
217 .name =
"ipv4-address-no-zone",
219 .plugin.id =
"ly2 ipv4-address-no-zone",
220 .plugin.lyb_size = lyplg_type_lyb_size_ipv4_address_no_zone,
221 .plugin.store = lyplg_type_store_ipv4_address_no_zone,
222 .plugin.validate_value = NULL,
223 .plugin.validate_tree = NULL,
224 .plugin.compare = lyplg_type_compare_ipv4_address_no_zone,
225 .plugin.sort = lyplg_type_sort_ipv4_address_no_zone,
226 .plugin.print = lyplg_type_print_ipv4_address_no_zone,
struct lysc_type * realtype
memset(value->fixed_mem, 0, LYD_VALUE_FIXED_MEM_SIZE)
LIBYANG_API_DECL LY_ERR lyplg_type_check_value_size(const char *type_name, LY_VALUE_FORMAT format, uint32_t value_size_bits, enum lyplg_lyb_size_type lyb_size_type, uint32_t lyb_fixed_size_bits, uint32_t *value_size, struct ly_err_item **err)
Check a value type in bits is correct and as expected.
lyplg_lyb_size_type
Type of the LYB size of a value of a particular type.
YANG extension compiled instance.
LY_ERR
libyang's error codes returned by the libyang functions.
uint8_t ly_bool
Type to indicate boolean value.
#define LYPLG_TYPE_STORE_DYNAMIC
Special lyd_value structure for ietf-inet-types ipv4-address-no-zone values.
struct lyplg_type_record plugins_ipv4_address_no_zone[]
Plugin information for ipv4-address-no-zone type implementation.
The main libyang public header.
YANG data representation.
Libyang full error structure.
#define LYD_VALUE_GET(value, type_val)
Get the value in format specific to the type.
LIBYANG_API_DECL LY_ERR ly_err_new(struct ly_err_item **err, LY_ERR ecode, LY_VECODE vecode, char *data_path, char *apptag, const char *err_format,...) _FORMAT_PRINTF(6
Create and fill error structure.
LIBYANG_API_DECL LY_ERR lydict_insert_zc(const struct ly_ctx *ctx, char *value, const char **str_p)
Insert string into dictionary - zerocopy version. If the string is already present, only a reference counter is incremented and no memory allocation is performed. This insert function variant avoids duplication of specified value - it is inserted into the dictionary directly.
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
#define LYPLG_TYPE_VAL_INLINE_PREPARE(storage, type_val)
Prepare value memory for storing a specific type value, may be allocated dynamically.
LIBYANG_API_DECL LY_ERR lyplg_type_dup_simple(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
Implementation of lyplg_type_dup_clb for a generic simple type.
LIBYANG_API_DECL void lyplg_type_free_simple(const struct ly_ctx *ctx, struct lyd_value *value)
Implementation of lyplg_type_free_clb for a generic simple type.
return memcmp(v1->data, v2->data, bitmap_size)
LIBYANG_API_DECL LY_ERR lyplg_type_check_hints(uint32_t hints, const char *value, uint32_t value_len, LY_DATA_TYPE type, int *base, struct ly_err_item **err)
Check that the type is suitable for the parser's hints (if any) in the specified format.
API for (user) types plugins.