blob: eb688d5319cd3a199a73ae7c2bf86e68ff5804c8 [file] [log] [blame]
Radek Krejci0935f412019-08-20 16:15:18 +02001/**
2 * @file plugins_exts.c
3 * @author Radek Krejci <rkrejci@cesnet.cz>
Michal Vaskoddd76592022-01-17 13:34:48 +01004 * @author Michal Vasko <mvasko@cesnet.cz>
5 * @brief helper functions for extension plugins
Radek Krejci0935f412019-08-20 16:15:18 +02006 *
Michal Vaskoddd76592022-01-17 13:34:48 +01007 * Copyright (c) 2019 - 2022 CESNET, z.s.p.o.
Radek Krejci0935f412019-08-20 16:15:18 +02008 *
9 * This source code is licensed under BSD 3-Clause License (the "License").
10 * You may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * https://opensource.org/licenses/BSD-3-Clause
14 */
Radek Krejci0935f412019-08-20 16:15:18 +020015
16#include "plugins_exts.h"
Radek Krejci77114102021-03-10 15:21:57 +010017#include "plugins_exts_compile.h"
18#include "plugins_exts_print.h"
Radek Krejci0935f412019-08-20 16:15:18 +020019
Radek Krejci47fab892020-11-05 17:02:41 +010020#include <stdint.h>
Radek Krejci535ea9f2020-05-29 16:01:05 +020021
Radek Krejci5f9a3672021-03-05 21:35:22 +010022#include "common.h"
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010023#include "printer_internal.h"
Radek Krejci5f9a3672021-03-05 21:35:22 +010024#include "schema_compile.h"
25
Jan Kundrátc53a7ec2021-12-09 16:01:19 +010026LIBYANG_API_DEF struct ly_ctx *
Radek Krejci5f9a3672021-03-05 21:35:22 +010027lysc_ctx_get_ctx(const struct lysc_ctx *ctx)
28{
29 return ctx->ctx;
30}
31
Jan Kundrátc53a7ec2021-12-09 16:01:19 +010032LIBYANG_API_DEF uint32_t *
Radek Krejci5f9a3672021-03-05 21:35:22 +010033lysc_ctx_get_options(const struct lysc_ctx *ctx)
34{
Michal Vasko7c565922021-06-10 14:58:27 +020035 return &((struct lysc_ctx *)ctx)->compile_opts;
Radek Krejci5f9a3672021-03-05 21:35:22 +010036}
37
Jan Kundrátc53a7ec2021-12-09 16:01:19 +010038LIBYANG_API_DEF const char *
Radek Krejci5f9a3672021-03-05 21:35:22 +010039lysc_ctx_get_path(const struct lysc_ctx *ctx)
40{
41 return ctx->path;
42}
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010043
Jan Kundrátc53a7ec2021-12-09 16:01:19 +010044LIBYANG_API_DEF struct ly_out **
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010045lys_ypr_ctx_get_out(const struct lyspr_ctx *ctx)
46{
47 return &((struct lyspr_ctx *)ctx)->out;
48}
49
Jan Kundrátc53a7ec2021-12-09 16:01:19 +010050LIBYANG_API_DEF uint32_t *
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010051lys_ypr_ctx_get_options(const struct lyspr_ctx *ctx)
52{
53 return &((struct lyspr_ctx *)ctx)->options;
54}
55
Jan Kundrátc53a7ec2021-12-09 16:01:19 +010056LIBYANG_API_DEF uint16_t *
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010057lys_ypr_ctx_get_level(const struct lyspr_ctx *ctx)
58{
59 return &((struct lyspr_ctx *)ctx)->level;
60}
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +010061
Michal Vasko6a914fb2022-01-17 10:36:14 +010062LIBYANG_API_DEF const struct lys_module *
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +010063lysc_ctx_get_cur_mod(const struct lysc_ctx *ctx)
64{
65 return ctx->cur_mod;
66}
67
Michal Vasko6a914fb2022-01-17 10:36:14 +010068LIBYANG_API_DEF struct lysp_module *
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +010069lysc_ctx_get_pmod(const struct lysc_ctx *ctx)
70{
71 return ctx->pmod;
72}
Michal Vaskoddd76592022-01-17 13:34:48 +010073
74LIBYANG_API_DEF LY_ERR
75lyplg_ext_get_data(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, void **ext_data, ly_bool *ext_data_free)
76{
77 if (!ctx->ext_clb) {
78 lyplg_ext_log(ext, LY_LLERR, LY_EINVAL, NULL, "Failed to get extension data, no callback set.");
79 return LY_EINVAL;
80 }
81
82 return ctx->ext_clb(ext, ctx->ext_clb_data, ext_data, ext_data_free);
83}