blob: 6fbe719c9e10e6bc4f4c0c99def8e0179c8b334f [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 */
14#include "common.h"
15
16#include "plugins_exts.h"
17
18#include "plugins_exts_nacm.c"
Radek Krejcid6b76452019-09-03 17:03:03 +020019#include "plugins_exts_metadata.c"
Radek Krejci0935f412019-08-20 16:15:18 +020020
21/**
22 * @brief list of all extension plugins implemented internally
23 */
Radek Krejcid6b76452019-09-03 17:03:03 +020024struct lyext_plugins_list lyext_plugins_internal[6] = {
Radek Krejci0935f412019-08-20 16:15:18 +020025 {"ietf-netconf-acm", "2012-02-22", "default-deny-write", &nacm_plugin},
26 {"ietf-netconf-acm", "2018-02-14", "default-deny-write", &nacm_plugin},
27 {"ietf-netconf-acm", "2012-02-22", "default-deny-all", &nacm_plugin},
28 {"ietf-netconf-acm", "2018-02-14", "default-deny-all", &nacm_plugin},
Radek Krejcid6b76452019-09-03 17:03:03 +020029 {"ietf-yang-metadata", "2016-08-05", "annotation", &metadata_plugin},
Radek Krejci0935f412019-08-20 16:15:18 +020030 {NULL, NULL, NULL, NULL} /* terminating item */
31};
32
33/* TODO support for external extension plugins */
34
35struct lyext_plugin *
36lyext_get_plugin(struct lysc_ext *ext)
37{
38 unsigned int u;
39
40 for (u = 0; lyext_plugins_internal[u].module; ++u) {
41 if (!strcmp(ext->name, lyext_plugins_internal[u].name) &&
42 !strcmp(ext->module->name, lyext_plugins_internal[u].module) &&
43 (!lyext_plugins_internal[u].revision || !strcmp(ext->module->revision, lyext_plugins_internal[u].revision))) {
44 /* we have the match */
45 return lyext_plugins_internal[u].plugin;
46 }
47 }
48
49 return NULL;
50}
51
52API const char *
53lyext_parent2str(LYEXT_PARENT type)
54{
55 switch(type) {
56 case LYEXT_PAR_MODULE:
57 return "module";
58 case LYEXT_PAR_NODE:
59 return "data node";
60 case LYEXT_PAR_INPUT:
61 return "input";
62 case LYEXT_PAR_OUTPUT:
63 return "output";
64 case LYEXT_PAR_TYPE:
65 return "type";
66 case LYEXT_PAR_TYPE_BIT:
67 return "bit";
68 case LYEXT_PAR_TYPE_ENUM:
69 return "enum";
70 case LYEXT_PAR_FEATURE:
71 return "feature";
72 case LYEXT_PAR_MUST:
73 return "must";
74 case LYEXT_PAR_PATTERN:
75 return "pattern";
76 case LYEXT_PAR_LENGTH:
77 return "length";
78 case LYEXT_PAR_RANGE:
79 return "range";
80 case LYEXT_PAR_WHEN:
81 return "when";
82 case LYEXT_PAR_IDENT:
83 return "identity";
84 case LYEXT_PAR_EXT:
85 return "extension instance";
86 case LYEXT_PAR_IMPORT:
87 return "import";
88/* YANG allows extension instances inside the following statements,
89 * but they do not have any meaning in current libyang
90 case LYEXT_PAR_TPDF:
91 return "typedef";
92 case LYEXT_PAR_EXTINST:
93 return "extension";
94 case LYEXT_PAR_REFINE:
95 return "refine";
96 case LYEXT_PAR_DEVIATION:
97 return "deviation";
98 case LYEXT_PAR_DEVIATE:
99 return "deviate";
100 case LYEXT_PAR_INCLUDE:
101 return "include";
102 case LYEXT_PAR_REVISION:
103 return "revision";
104 */
105 default:
106 return "unknown";
107 }
108}