blob: 16d0d927e894711c7b32496ea5b0a27a279fb6d6 [file] [log] [blame]
Michal Vaskoc6cd3f02018-03-02 14:07:42 +01001/**
2 * @file plugin_config.h
3 * @author Michal Vasko <mvasko@cesnet.cz>
4 * @brief libyang plugin config file
5 *
6 * Copyright (c) 2018 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 */
14
15#ifndef LY_PLUGIN_CONFIG_H_
16#define LY_PLUGIN_CONFIG_H_
17
18#define LYEXT_PLUGINS_DIR "@EXTENSIONS_PLUGINS_DIR_MACRO@" /**< directory with YANG extension plugins */
19#define LY_USER_TYPES_PLUGINS_DIR "@USER_TYPES_PLUGINS_DIR_MACRO@" /**< directory with user YANG types plugins */
20
21#if defined __linux__ || defined __unix__
22# define LY_PLUGIN_SUFFIX ".so"
23# define LY_PLUGIN_SUFFIX_LEN 3
24#elif defined __APPLE__
25# define LY_PLUGIN_SUFFIX ".dylib"
26# define LY_PLUGIN_SUFFIX_LEN 6
27#endif
28
Mislav Novakovic61c79082018-05-21 13:08:24 +020029#ifdef STATIC
30@EXTERN_EXTENSIONS_LIST@
31@EXTERN_USER_TYPE_LIST@
32
Mislav Novakovic3bef44a2018-05-23 18:08:52 +020033int lytype_size(struct lytype_plugin_list plugin[]) {
34 struct lytype_plugin_list *tmp;
35 int i = 0;
36 while (1) {
37 tmp = &plugin[i];
38 if (!tmp) break;
39 if (!tmp->module && !tmp->revision && !tmp->name && !tmp->store_clb && !tmp->free_clb) break;
40 i++;
41 }
42
43 return i;
44}
45
46void lytype_add(struct lytype_plugin_list *type_plugins, uint16_t *type_plugins_count, struct lytype_plugin_list plugin[]) {
47 struct lytype_plugin_list *tmp;
48 int i = 0;
49 while (1) {
50 tmp = &plugin[i];
51 if (!tmp) break;
52 if (!tmp->module && !tmp->revision && !tmp->name && !tmp->store_clb && !tmp->free_clb) break;
53 i++;
54 memcpy(&type_plugins[*type_plugins_count], tmp, sizeof *tmp);
55 (*type_plugins_count)++;
56 }
57
58 return;
59}
60
61
62int lyext_size(struct lyext_plugin_list plugin[]) {
63 struct lyext_plugin_list *tmp;
64 int i = 0;
65 while (1) {
66 tmp = &plugin[i];
67 if (!tmp) break;
68 if (!tmp->module && !tmp->revision && !tmp->name && !tmp->plugin) break;
69 i++;
70 }
71
72 return i;
73}
74
75void lyext_add(struct lyext_plugin_list *ext_plugins, uint16_t *ext_plugins_count, struct lyext_plugin_list plugin[]) {
76 struct lyext_plugin_list *tmp;
77 int i = 0;
78 while (1) {
79 tmp = &plugin[i];
80 if (!tmp) break;
81 if (!tmp->module && !tmp->revision && !tmp->name && !tmp->plugin) break;
82 i++;
83 memcpy(&ext_plugins[*ext_plugins_count], tmp, sizeof *tmp);
84 (*ext_plugins_count)++;
85 }
86
87 return;
88}
89
Mislav Novakovic61c79082018-05-21 13:08:24 +020090struct lyext_plugin_list *static_load_lyext_plugins(uint16_t *count)
91{
92 struct lyext_plugin_list *plugin;
93 uint16_t size = @EXTENSIONS_LIST_SIZE@;
94
95 plugin = malloc(size * (sizeof *plugin));
96 if (!plugin) {
97 LOGMEM(NULL);
98 return NULL;
99 }
100
Mislav Novakovic3bef44a2018-05-23 18:08:52 +0200101 *count = 0;
Mislav Novakovic61c79082018-05-21 13:08:24 +0200102@MEMCPY_EXTENSIONS_LIST@
103 return plugin;
104}
105
106struct lytype_plugin_list *static_load_lytype_plugins(uint16_t *count)
107{
108 struct lytype_plugin_list *plugin;
109 uint16_t size = @USER_TYPE_LIST_SIZE@;
110
111 plugin = malloc(size * (sizeof *plugin));
112 if (!plugin) {
113 LOGMEM(NULL);
114 return NULL;
115 }
116
Mislav Novakovic3bef44a2018-05-23 18:08:52 +0200117 *count = 0;
Mislav Novakovic61c79082018-05-21 13:08:24 +0200118@MEMCPY_USER_TYPE_LIST@
119 return plugin;
120}
Mislav Novakovic74726932018-06-04 13:14:03 +0200121
122uint16_t static_loaded_plugins_count = @STATIC_LOADED_PLUGINS_COUNT@;
123char *static_loaded_plugins[] = {@STATIC_LOADED_PLUGINS@};
124
Mislav Novakovic61c79082018-05-21 13:08:24 +0200125#endif /* STATIC */
126
Michal Vaskoc6cd3f02018-03-02 14:07:42 +0100127#endif /* LY_PLUGIN_CONFIG_H_ */