libyang 3.4.2
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
15#include "plugins_types.h"
16
17#include <stdlib.h>
18#include <string.h>
19
20#include "libyang.h"
21
22#include "compat.h"
23#include "ly_common.h"
24#include "plugins_internal.h" /* LY_TYPE_*_STR */
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 = "2024-07-09",
87 .name = "time-period",
88
89 .plugin.id = "libyang 2 - time-period, version 1",
90 .plugin.store = lyplg_type_store_string,
91 .plugin.validate = NULL,
92 .plugin.compare = lyplg_type_compare_simple,
93 .plugin.sort = lyplg_type_sort_time_period,
94 .plugin.print = lyplg_type_print_simple,
95 .plugin.duplicate = lyplg_type_dup_simple,
96 .plugin.free = lyplg_type_free_simple,
97 .plugin.lyb_data_len = -1,
98 },
99 {0}
100};
libyang context handler.
const char *const char * revision
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, size_t *value_len)
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 LY_ERR lyplg_type_store_string(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, size_t value_len, 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.
The main libyang public header.
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:571