blob: 11ada75867ccff65a327620870bb51aa210787c4 [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 */
Radek Krejci0935f412019-08-20 16:15:18 +020014
15#include "plugins_exts.h"
Radek Krejcic0c872a2021-03-10 13:30:08 +010016#include "plugins_exts_internal.h"
Radek Krejci0935f412019-08-20 16:15:18 +020017
Radek Krejci47fab892020-11-05 17:02:41 +010018#include <stdint.h>
Radek Krejci535ea9f2020-05-29 16:01:05 +020019#include <string.h>
20
Radek Krejcid6b76452019-09-03 17:03:03 +020021#include "plugins_exts_metadata.c"
Radek Krejci535ea9f2020-05-29 16:01:05 +020022#include "plugins_exts_nacm.c"
Radek Krejci5fa32a32021-02-08 18:12:38 +010023#include "plugins_exts_yangdata.c"
Radek Krejci0935f412019-08-20 16:15:18 +020024
Radek Krejci5f9a3672021-03-05 21:35:22 +010025/* internal libyang headers - do not make them accessible to the extension plugins in plugins_exts_*.c */
26#include "common.h"
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010027#include "printer_internal.h"
Radek Krejci5f9a3672021-03-05 21:35:22 +010028#include "schema_compile.h"
29
Radek Krejci0935f412019-08-20 16:15:18 +020030/**
31 * @brief list of all extension plugins implemented internally
32 */
Radek Krejcic0c872a2021-03-10 13:30:08 +010033struct lyext_plugin_record lyext_plugins_internal[] = {
Radek Krejci0935f412019-08-20 16:15:18 +020034 {"ietf-netconf-acm", "2012-02-22", "default-deny-write", &nacm_plugin},
35 {"ietf-netconf-acm", "2018-02-14", "default-deny-write", &nacm_plugin},
36 {"ietf-netconf-acm", "2012-02-22", "default-deny-all", &nacm_plugin},
37 {"ietf-netconf-acm", "2018-02-14", "default-deny-all", &nacm_plugin},
Radek Krejcid6b76452019-09-03 17:03:03 +020038 {"ietf-yang-metadata", "2016-08-05", "annotation", &metadata_plugin},
Radek Krejci5fa32a32021-02-08 18:12:38 +010039 {"ietf-restconf", "2017-01-26", "yang-data", &yangdata_plugin},
Radek Krejci0935f412019-08-20 16:15:18 +020040 {NULL, NULL, NULL, NULL} /* terminating item */
41};
42
43/* TODO support for external extension plugins */
44
45struct lyext_plugin *
46lyext_get_plugin(struct lysc_ext *ext)
47{
Radek Krejci1deb5be2020-08-26 16:43:36 +020048 for (uint8_t u = 0; lyext_plugins_internal[u].module; ++u) {
Radek Krejci0935f412019-08-20 16:15:18 +020049 if (!strcmp(ext->name, lyext_plugins_internal[u].name) &&
50 !strcmp(ext->module->name, lyext_plugins_internal[u].module) &&
51 (!lyext_plugins_internal[u].revision || !strcmp(ext->module->revision, lyext_plugins_internal[u].revision))) {
52 /* we have the match */
53 return lyext_plugins_internal[u].plugin;
54 }
55 }
56
57 return NULL;
58}
Radek Krejci5f9a3672021-03-05 21:35:22 +010059
60API struct ly_ctx *
61lysc_ctx_get_ctx(const struct lysc_ctx *ctx)
62{
63 return ctx->ctx;
64}
65
66API uint32_t *
67lysc_ctx_get_options(const struct lysc_ctx *ctx)
68{
69 return &((struct lysc_ctx *)ctx)->options;
70}
71
72API const char *
73lysc_ctx_get_path(const struct lysc_ctx *ctx)
74{
75 return ctx->path;
76}
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010077
78API struct ly_out **
79lys_ypr_ctx_get_out(const struct lyspr_ctx *ctx)
80{
81 return &((struct lyspr_ctx *)ctx)->out;
82}
83
84API uint32_t *
85lys_ypr_ctx_get_options(const struct lyspr_ctx *ctx)
86{
87 return &((struct lyspr_ctx *)ctx)->options;
88}
89
90API uint16_t *
91lys_ypr_ctx_get_level(const struct lyspr_ctx *ctx)
92{
93 return &((struct lyspr_ctx *)ctx)->level;
94}