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> |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
| 5 | * @brief helper functions for extension plugins |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 6 | * |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 7 | * Copyright (c) 2019 - 2022 CESNET, z.s.p.o. |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 8 | * |
| 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 Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 15 | |
| 16 | #include "plugins_exts.h" |
Radek Krejci | 7711410 | 2021-03-10 15:21:57 +0100 | [diff] [blame] | 17 | #include "plugins_exts_compile.h" |
| 18 | #include "plugins_exts_print.h" |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 19 | |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 20 | #include <stdint.h> |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 21 | |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 22 | #include "common.h" |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 23 | #include "printer_internal.h" |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 24 | #include "schema_compile.h" |
| 25 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 26 | LIBYANG_API_DEF struct ly_ctx * |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 27 | lysc_ctx_get_ctx(const struct lysc_ctx *ctx) |
| 28 | { |
| 29 | return ctx->ctx; |
| 30 | } |
| 31 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 32 | LIBYANG_API_DEF uint32_t * |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 33 | lysc_ctx_get_options(const struct lysc_ctx *ctx) |
| 34 | { |
Michal Vasko | 7c56592 | 2021-06-10 14:58:27 +0200 | [diff] [blame] | 35 | return &((struct lysc_ctx *)ctx)->compile_opts; |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 36 | } |
| 37 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 38 | LIBYANG_API_DEF const char * |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 39 | lysc_ctx_get_path(const struct lysc_ctx *ctx) |
| 40 | { |
| 41 | return ctx->path; |
| 42 | } |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 43 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 44 | LIBYANG_API_DEF struct ly_out ** |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 45 | lys_ypr_ctx_get_out(const struct lyspr_ctx *ctx) |
| 46 | { |
| 47 | return &((struct lyspr_ctx *)ctx)->out; |
| 48 | } |
| 49 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 50 | LIBYANG_API_DEF uint32_t * |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 51 | lys_ypr_ctx_get_options(const struct lyspr_ctx *ctx) |
| 52 | { |
| 53 | return &((struct lyspr_ctx *)ctx)->options; |
| 54 | } |
| 55 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 56 | LIBYANG_API_DEF uint16_t * |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 57 | lys_ypr_ctx_get_level(const struct lyspr_ctx *ctx) |
| 58 | { |
| 59 | return &((struct lyspr_ctx *)ctx)->level; |
| 60 | } |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 61 | |
Michal Vasko | 6a914fb | 2022-01-17 10:36:14 +0100 | [diff] [blame] | 62 | LIBYANG_API_DEF const struct lys_module * |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 63 | lysc_ctx_get_cur_mod(const struct lysc_ctx *ctx) |
| 64 | { |
| 65 | return ctx->cur_mod; |
| 66 | } |
| 67 | |
Michal Vasko | 6a914fb | 2022-01-17 10:36:14 +0100 | [diff] [blame] | 68 | LIBYANG_API_DEF struct lysp_module * |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 69 | lysc_ctx_get_pmod(const struct lysc_ctx *ctx) |
| 70 | { |
| 71 | return ctx->pmod; |
| 72 | } |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 73 | |
| 74 | LIBYANG_API_DEF LY_ERR |
| 75 | lyplg_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 | } |