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" |
Radek Krejci | c0c872a | 2021-03-10 13:30:08 +0100 | [diff] [blame] | 16 | #include "plugins_exts_internal.h" |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 17 | |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 18 | #include <stdint.h> |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 19 | #include <string.h> |
| 20 | |
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 | |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame^] | 25 | /* internal libyang headers - do not make them accessible to the extension plugins in plugins_exts_*.c */ |
| 26 | #include "common.h" |
| 27 | #include "schema_compile.h" |
| 28 | |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 29 | /** |
| 30 | * @brief list of all extension plugins implemented internally |
| 31 | */ |
Radek Krejci | c0c872a | 2021-03-10 13:30:08 +0100 | [diff] [blame] | 32 | struct lyext_plugin_record lyext_plugins_internal[] = { |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 33 | {"ietf-netconf-acm", "2012-02-22", "default-deny-write", &nacm_plugin}, |
| 34 | {"ietf-netconf-acm", "2018-02-14", "default-deny-write", &nacm_plugin}, |
| 35 | {"ietf-netconf-acm", "2012-02-22", "default-deny-all", &nacm_plugin}, |
| 36 | {"ietf-netconf-acm", "2018-02-14", "default-deny-all", &nacm_plugin}, |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 37 | {"ietf-yang-metadata", "2016-08-05", "annotation", &metadata_plugin}, |
Radek Krejci | 5fa32a3 | 2021-02-08 18:12:38 +0100 | [diff] [blame] | 38 | {"ietf-restconf", "2017-01-26", "yang-data", &yangdata_plugin}, |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 39 | {NULL, NULL, NULL, NULL} /* terminating item */ |
| 40 | }; |
| 41 | |
| 42 | /* TODO support for external extension plugins */ |
| 43 | |
| 44 | struct lyext_plugin * |
| 45 | lyext_get_plugin(struct lysc_ext *ext) |
| 46 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 47 | for (uint8_t u = 0; lyext_plugins_internal[u].module; ++u) { |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 48 | if (!strcmp(ext->name, lyext_plugins_internal[u].name) && |
| 49 | !strcmp(ext->module->name, lyext_plugins_internal[u].module) && |
| 50 | (!lyext_plugins_internal[u].revision || !strcmp(ext->module->revision, lyext_plugins_internal[u].revision))) { |
| 51 | /* we have the match */ |
| 52 | return lyext_plugins_internal[u].plugin; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return NULL; |
| 57 | } |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame^] | 58 | |
| 59 | API struct ly_ctx * |
| 60 | lysc_ctx_get_ctx(const struct lysc_ctx *ctx) |
| 61 | { |
| 62 | return ctx->ctx; |
| 63 | } |
| 64 | |
| 65 | API uint32_t * |
| 66 | lysc_ctx_get_options(const struct lysc_ctx *ctx) |
| 67 | { |
| 68 | return &((struct lysc_ctx *)ctx)->options; |
| 69 | } |
| 70 | |
| 71 | API const char * |
| 72 | lysc_ctx_get_path(const struct lysc_ctx *ctx) |
| 73 | { |
| 74 | return ctx->path; |
| 75 | } |