blob: 2bf6889817ab0394ee120836ce96eeaa1fadfd36 [file] [log] [blame]
Radek Krejci0935f412019-08-20 16:15:18 +02001/**
2 * @file plugins_exts.c
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief Internally implemented YANG extensions.
5 *
6 * Copyright (c) 2019 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
Radek Krejci0935f412019-08-20 16:15:18 +020014
15#include "plugins_exts.h"
16
Radek Krejci47fab892020-11-05 17:02:41 +010017#include <stdint.h>
Radek Krejci535ea9f2020-05-29 16:01:05 +020018#include <string.h>
19
20#include "common.h"
Radek Krejcid6b76452019-09-03 17:03:03 +020021#include "plugins_exts_metadata.c"
Radek Krejci535ea9f2020-05-29 16:01:05 +020022#include "plugins_exts_nacm.c"
Radek Krejci0935f412019-08-20 16:15:18 +020023
24/**
25 * @brief list of all extension plugins implemented internally
26 */
Radek Krejcid6b76452019-09-03 17:03:03 +020027struct lyext_plugins_list lyext_plugins_internal[6] = {
Radek Krejci0935f412019-08-20 16:15:18 +020028 {"ietf-netconf-acm", "2012-02-22", "default-deny-write", &nacm_plugin},
29 {"ietf-netconf-acm", "2018-02-14", "default-deny-write", &nacm_plugin},
30 {"ietf-netconf-acm", "2012-02-22", "default-deny-all", &nacm_plugin},
31 {"ietf-netconf-acm", "2018-02-14", "default-deny-all", &nacm_plugin},
Radek Krejcid6b76452019-09-03 17:03:03 +020032 {"ietf-yang-metadata", "2016-08-05", "annotation", &metadata_plugin},
Radek Krejci0935f412019-08-20 16:15:18 +020033 {NULL, NULL, NULL, NULL} /* terminating item */
34};
35
36/* TODO support for external extension plugins */
37
38struct lyext_plugin *
39lyext_get_plugin(struct lysc_ext *ext)
40{
Radek Krejci1deb5be2020-08-26 16:43:36 +020041 for (uint8_t u = 0; lyext_plugins_internal[u].module; ++u) {
Radek Krejci0935f412019-08-20 16:15:18 +020042 if (!strcmp(ext->name, lyext_plugins_internal[u].name) &&
43 !strcmp(ext->module->name, lyext_plugins_internal[u].module) &&
44 (!lyext_plugins_internal[u].revision || !strcmp(ext->module->revision, lyext_plugins_internal[u].revision))) {
45 /* we have the match */
46 return lyext_plugins_internal[u].plugin;
47 }
48 }
49
50 return NULL;
51}
52
53API const char *
54lyext_parent2str(LYEXT_PARENT type)
55{
Michal Vaskod989ba02020-08-24 10:59:24 +020056 switch (type) {
Radek Krejci0935f412019-08-20 16:15:18 +020057 case LYEXT_PAR_MODULE:
58 return "module";
59 case LYEXT_PAR_NODE:
60 return "data node";
61 case LYEXT_PAR_INPUT:
62 return "input";
63 case LYEXT_PAR_OUTPUT:
64 return "output";
65 case LYEXT_PAR_TYPE:
66 return "type";
67 case LYEXT_PAR_TYPE_BIT:
68 return "bit";
69 case LYEXT_PAR_TYPE_ENUM:
70 return "enum";
Radek Krejci0935f412019-08-20 16:15:18 +020071 case LYEXT_PAR_MUST:
72 return "must";
73 case LYEXT_PAR_PATTERN:
74 return "pattern";
75 case LYEXT_PAR_LENGTH:
76 return "length";
77 case LYEXT_PAR_RANGE:
78 return "range";
79 case LYEXT_PAR_WHEN:
80 return "when";
81 case LYEXT_PAR_IDENT:
82 return "identity";
83 case LYEXT_PAR_EXT:
84 return "extension instance";
85 case LYEXT_PAR_IMPORT:
86 return "import";
Radek Krejci0f969882020-08-21 16:56:47 +020087 /* YANG allows extension instances inside the following statements,
88 * but they do not have any meaning in current libyang
89 case LYEXT_PAR_TPDF:
90 return "typedef";
91 case LYEXT_PAR_EXTINST:
92 return "extension";
93 case LYEXT_PAR_REFINE:
94 return "refine";
95 case LYEXT_PAR_DEVIATION:
96 return "deviation";
97 case LYEXT_PAR_DEVIATE:
98 return "deviate";
99 case LYEXT_PAR_INCLUDE:
100 return "include";
101 case LYEXT_PAR_REVISION:
102 return "revision";
103 */
Radek Krejci0935f412019-08-20 16:15:18 +0200104 default:
105 return "unknown";
106 }
107}