blob: 59ea2bf0f4648f42aa34acf4575d73b65d6d3b7f [file] [log] [blame]
Radek Krejcid6b76452019-09-03 17:03:03 +02001/**
aPiecek023f83a2021-05-11 07:37:03 +02002 * @file metadata.h
Radek Krejcid6b76452019-09-03 17:03:03 +02003 * @author Radek Krejci <rkrejci@cesnet.cz>
Michal Vaskob4750962022-10-06 15:33:35 +02004 * @author Michal Vasko <mvasko@cesnet.cz>
Radek Krejcid6b76452019-09-03 17:03:03 +02005 * @brief ietf-yang-metadata API
6 *
Michal Vaskob4750962022-10-06 15:33:35 +02007 * Copyright (c) 2019 - 2022 CESNET, z.s.p.o.
Radek Krejcid6b76452019-09-03 17:03:03 +02008 *
9 * This source code is licensed under BSD 3-Clause License (the "License").
10 * You may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * https://opensource.org/licenses/BSD-3-Clause
14 */
15
16#ifndef LY_PLUGINS_EXTS_METADATA_H_
17#define LY_PLUGINS_EXTS_METADATA_H_
18
Michal Vaskob4750962022-10-06 15:33:35 +020019#include "plugins_exts.h"
20#include "tree_data.h"
21
Radek Krejcid6b76452019-09-03 17:03:03 +020022#ifdef __cplusplus
23extern "C" {
24#endif
25
Michal Vaskob4750962022-10-06 15:33:35 +020026/**
27 * @brief Metadata structure.
28 *
29 * The structure provides information about metadata of a data element. Such attributes must map to
30 * annotations as specified in RFC 7952. The only exception is the filter type (in NETCONF get operations)
31 * and edit-config's operation attributes. In XML, they are represented as standard XML attributes. In JSON,
32 * they are represented as JSON elements starting with the '@' character (for more information, see the
33 * YANG metadata RFC.
34 *
35 */
36struct lyd_meta {
37 struct lyd_node *parent; /**< data node where the metadata is placed */
38 struct lyd_meta *next; /**< pointer to the next metadata of the same element */
39 struct lysc_ext_instance *annotation; /**< pointer to the annotation's definition */
40 const char *name; /**< metadata name */
41 struct lyd_value value; /**< metadata value representation */
42};
43
44/**
45 * @brief Get the (canonical) value of a metadata node.
46 *
47 * @param[in] meta Metadata node to use.
48 * @return Canonical value.
49 */
50static inline const char *
51lyd_get_meta_value(const struct lyd_meta *meta)
52{
53 if (meta) {
54 const struct lyd_value *value = &meta->value;
55
56 return value->_canonical ? value->_canonical : lyd_value_get_canonical(meta->annotation->module->ctx, value);
57 }
58
59 return NULL;
60}
61
Radek Krejcid6b76452019-09-03 17:03:03 +020062#ifdef __cplusplus
63}
64#endif
65
66#endif /* LY_PLUGINS_EXTS_METADATA_H_ */