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