Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1 | /** |
aPiecek | 023f83a | 2021-05-11 07:37:03 +0200 | [diff] [blame] | 2 | * @file metadata.h |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Michal Vasko | b475096 | 2022-10-06 15:33:35 +0200 | [diff] [blame] | 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 5 | * @brief ietf-yang-metadata API |
| 6 | * |
Michal Vasko | b475096 | 2022-10-06 15:33:35 +0200 | [diff] [blame] | 7 | * Copyright (c) 2019 - 2022 CESNET, z.s.p.o. |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 8 | * |
| 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 Vasko | b475096 | 2022-10-06 15:33:35 +0200 | [diff] [blame] | 19 | #include "plugins_exts.h" |
| 20 | #include "tree_data.h" |
| 21 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
Michal Vasko | b475096 | 2022-10-06 15:33:35 +0200 | [diff] [blame] | 26 | /** |
| 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 | */ |
| 36 | struct 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 | */ |
| 50 | static inline const char * |
| 51 | lyd_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 Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 62 | #ifdef __cplusplus |
| 63 | } |
| 64 | #endif |
| 65 | |
| 66 | #endif /* LY_PLUGINS_EXTS_METADATA_H_ */ |