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