libyang 6.4.3
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
Loading...
Searching...
No Matches
time_period.c
Go to the documentation of this file.
1
16#include "plugins_types.h"
17
18#include <stdlib.h>
19#include <string.h>
20
21#include "compat.h"
22#include "dict.h"
23#include "ly_common.h"
24#include "plugins_internal.h"
25
40static int
41lyplg_type_sort_time_period(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
42{
43 const char *value1, *value2;
44 char unit1, unit2;
45 long v1, v2;
46
47 value1 = lyd_value_get_canonical(ctx, val1);
48 value2 = lyd_value_get_canonical(ctx, val2);
49
50 /* get the units (last character) and the values (all characters except the last one) */
51 unit1 = value1[strlen(value1) - 1];
52 unit2 = value2[strlen(value2) - 1];
53 v1 = strtol(value1, NULL, 10);
54 v2 = strtol(value2, NULL, 10);
55
56 /* descending order */
57 if (unit1 == unit2) {
58 if (v1 > v2) {
59 return -1;
60 } else if (v1 == v2) {
61 return 0;
62 } else {
63 return 1;
64 }
65 } else if (unit1 == 'm') {
66 return -1;
67 } else if ((unit1 == 'w') && (unit2 != 'm')) {
68 return -1;
69 } else if ((unit1 == 'd') && (unit2 == 'h')) {
70 return -1;
71 } else {
72 return 1;
73 }
74}
75
84 {
85 .module = "libnetconf2-netconf-server",
86 .revision = NULL,
87 .name = "time-period",
88
89 .plugin.id = "ly2 time-period",
90 .plugin.lyb_size = lyplg_type_lyb_size_variable_bytes,
91 .plugin.store = lyplg_type_store_string,
92 .plugin.validate_value = NULL,
93 .plugin.validate_tree = NULL,
94 .plugin.compare = lyplg_type_compare_simple,
95 .plugin.sort = lyplg_type_sort_time_period,
96 .plugin.print = lyplg_type_print_simple,
97 .plugin.duplicate = lyplg_type_dup_simple,
98 .plugin.free = lyplg_type_free_simple,
99 },
100 {0}
101};
libyang dictionary
libyang context handler.
const char *const char * revision
LIBYANG_API_DECL LY_ERR lyplg_type_store_string(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint64_t value_size_bits, uint32_t options, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node, struct lyd_value *storage, struct lys_glob_unres *unres, struct ly_err_item **err)
Implementation of lyplg_type_store_clb for the built-in string type.
LIBYANG_API_DECL const void * lyplg_type_print_simple(const struct ly_ctx *ctx, const struct lyd_value *value, LY_VALUE_FORMAT format, void *prefix_data, ly_bool *dynamic, uint64_t *value_size_bits)
Implementation of lyplg_type_print_clb for a generic simple type.
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.
LIBYANG_API_DECL LY_ERR lyplg_type_compare_simple(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_compare_clb for a generic simple type.
LIBYANG_API_DECL void lyplg_type_lyb_size_variable_bytes(const struct lysc_type *type, enum lyplg_lyb_size_type *size_type, uint64_t *fixed_size_bits)
Implementation of lyplg_type_lyb_size_clb for a type with variable length rounded to bytes.
API for (user) types plugins.
const struct lyplg_type_record plugins_time_period[]
Plugin information for time-period type implementation.
Definition time_period.c:83
LIBYANG_API_DECL const char * lyd_value_get_canonical(const struct ly_ctx *ctx, const struct lyd_value *value)
Get the (canonical) value of a lyd_value.
YANG data representation.
Definition tree_data.h:610