1 /*
2 * The olsr.org Optimized Link-State Routing daemon (olsrd)
3 *
4 * (c) by the OLSR project
5 *
6 * See our Git repository to find out who worked on this file
7 * and thus is a copyright holder on it.
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 *
15 * * Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 * * Neither the name of olsr.org, olsrd nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 *
38 * Visit http://www.olsr.org for more information.
39 *
40 * If you find this software useful feel free to make a donation
41 * to the project. For more information see the website or contact
42 * the copyright holders.
43 *
44 */
45
46 /*
47 * Example plugin for olsrd.org OLSR daemon
48 * Only the bare minimum
49 */
50 #include "mini_plugin.h"
51
52 #include <stdio.h>
53 #include <string.h>
54
55 #include "olsr.h"
56 #include "builddata.h"
57 #include "olsrd_plugin.h"
58
59 #define PLUGIN_NAME "OLSRD mini plugin"
60 #define PLUGIN_INTERFACE_VERSION 5
61
62 /****************************************************************************
63 * Functions that the plugin MUST provide *
64 ****************************************************************************/
65
66 /**
67 * Plugin interface version
68 * Used by main olsrd to check plugin interface version
69 */
70 int
olsrd_plugin_interface_version(void)71 olsrd_plugin_interface_version(void)
72 {
73 return PLUGIN_INTERFACE_VERSION;
74 }
75
76 static int
set_plugin_test(const char * value,void * data,set_plugin_parameter_addon addon)77 set_plugin_test(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
78 {
79 printf("\n*** MINI: parameter test: %s\n", value);
80 return 0;
81 }
82
83 /**
84 * Register parameters from config file
85 * Called for all plugin parameters
86 */
87 static const struct olsrd_plugin_parameters plugin_parameters[] = {
88 {.name = "test",.set_plugin_parameter = &set_plugin_test,.data = NULL},
89 };
90
91 void
olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters ** params,int * size)92 olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
93 {
94 *params = plugin_parameters;
95 *size = sizeof(plugin_parameters) / sizeof(*plugin_parameters);
96 }
97
98 /**
99 * Initialize plugin
100 * Called after all parameters are passed
101 */
102 int
olsrd_plugin_init(void)103 olsrd_plugin_init(void)
104 {
105 printf("*** MINI: plugin_init\n");
106
107 /* call a function from main olsrd */
108 olsr_printf(2, "*** MINI: printed this with olsr_printf\n");
109
110 return 1;
111 }
112
113 /****************************************************************************
114 * Optional private constructor and destructor functions *
115 ****************************************************************************/
116
117 /* attention: make static to avoid name clashes */
118
119 static void my_init(void) __attribute__ ((constructor));
120 static void my_fini(void) __attribute__ ((destructor));
121
122 /**
123 * Optional Private Constructor
124 */
125 static void
my_init(void)126 my_init(void)
127 {
128 /* Print plugin info to stdout */
129 olsr_printf(0, "%s (%s)\n", PLUGIN_NAME, git_descriptor);
130
131 printf("*** MINI: constructor\n");
132 }
133
134 /**
135 * Optional Private Destructor
136 */
137 static void
my_fini(void)138 my_fini(void)
139 {
140 printf("*** MINI: destructor\n");
141 }
142
143 /*
144 * Local Variables:
145 * c-basic-offset: 2
146 * indent-tabs-mode: nil
147 * End:
148 */
149