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