20 # include <winsock2.h>
21 # include <ws2tcpip.h>
23 # include <arpa/inet.h>
24 # if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__)
25 # include <netinet/in.h>
26 # include <sys/socket.h>
52 lyplg_type_store_ipv4_address_no_zone(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value,
53 size_t value_len, uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
54 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
62 memset(storage, 0,
sizeof *storage);
64 LY_CHECK_ERR_GOTO(!val, ret =
LY_EMEM, cleanup);
71 "(expected 4).", value_len);
76 memcpy(&val->
addr, value, 4);
84 LY_CHECK_GOTO(ret, cleanup);
90 LY_CHECK_GOTO(ret, cleanup);
95 LY_CHECK_GOTO(ret, cleanup);
99 value = strndup(value, value_len);
100 LY_CHECK_ERR_GOTO(!value, ret =
LY_EMEM, cleanup);
106 if (!inet_pton(AF_INET, value, &val->
addr)) {
113 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
114 LY_CHECK_GOTO(ret, cleanup);
117 if (options & LYPLG_TYPE_STORE_DYNAMIC) {
131 lyplg_type_compare_ipv4_address_no_zone(
const struct lyd_value *val1,
const struct lyd_value *val2)
153 void *UNUSED(prefix_data),
ly_bool *dynamic,
size_t *value_len)
170 ret = malloc(INET_ADDRSTRLEN);
171 LY_CHECK_RET(!ret, NULL);
174 if (!inet_ntop(AF_INET, &val->
addr, ret, INET_ADDRSTRLEN)) {
176 LOGERR(ctx,
LY_EVALID,
"Failed to get IPv4 address in string (%s).", strerror(errno));
206 .
module =
"ietf-inet-types",
207 .revision =
"2013-07-15",
208 .name =
"ipv4-address-no-zone",
210 .plugin.id =
"libyang 2 - ipv4-address-no-zone, version 1",
211 .plugin.store = lyplg_type_store_ipv4_address_no_zone,
212 .plugin.validate = NULL,
213 .plugin.compare = lyplg_type_compare_ipv4_address_no_zone,
215 .plugin.print = lyplg_type_print_ipv4_address_no_zone,
218 .plugin.lyb_data_len = 4,
struct lysc_type * realtype
LIBYANG_API_DECL LY_ERR ly_err_new(struct ly_err_item **err, LY_ERR ecode, LY_VECODE vecode, char *path, char *apptag, const char *err_format,...) _FORMAT_PRINTF(6
Create and fill error structure.
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.
struct lysc_pattern ** patterns
struct lysc_range * length
YANG data representation.
LIBYANG_API_DECL LY_ERR lyplg_type_validate_patterns(struct lysc_pattern **patterns, const char *str, size_t str_len, struct ly_err_item **err)
Data type validator for pattern-restricted string values.
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 lyplg_type_check_hints(uint32_t hints, const char *value, size_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.
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.
LY_ERR
libyang's error codes returned by the libyang functions.
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.
API for (user) types plugins.
LIBYANG_API_DECL LY_ERR lyplg_type_validate_range(LY_DATA_TYPE basetype, struct lysc_range *range, int64_t value, const char *strval, size_t strval_len, struct ly_err_item **err)
Data type validator for a range/length-restricted values.