summaryrefslogtreecommitdiff
path: root/src/gnsrecord/gnsrecord.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnsrecord/gnsrecord.c')
-rw-r--r--src/gnsrecord/gnsrecord.c139
1 files changed, 69 insertions, 70 deletions
diff --git a/src/gnsrecord/gnsrecord.c b/src/gnsrecord/gnsrecord.c
index a4e8624e8..7672a7b00 100644
--- a/src/gnsrecord/gnsrecord.c
+++ b/src/gnsrecord/gnsrecord.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file gnsrecord/gnsrecord.c 22 * @file gnsrecord/gnsrecord.c
@@ -32,14 +32,13 @@
32#include "gnunet_gnsrecord_plugin.h" 32#include "gnunet_gnsrecord_plugin.h"
33#include "gnunet_tun_lib.h" 33#include "gnunet_tun_lib.h"
34 34
35#define LOG(kind,...) GNUNET_log_from (kind, "gnsrecord",__VA_ARGS__) 35#define LOG(kind, ...) GNUNET_log_from(kind, "gnsrecord", __VA_ARGS__)
36 36
37 37
38/** 38/**
39 * Handle for a plugin. 39 * Handle for a plugin.
40 */ 40 */
41struct Plugin 41struct Plugin {
42{
43 /** 42 /**
44 * Name of the shared library. 43 * Name of the shared library.
45 */ 44 */
@@ -76,20 +75,20 @@ static int once;
76 * @param lib_ret the plugin API 75 * @param lib_ret the plugin API
77 */ 76 */
78static void 77static void
79add_plugin (void *cls, 78add_plugin(void *cls,
80 const char *library_name, 79 const char *library_name,
81 void *lib_ret) 80 void *lib_ret)
82{ 81{
83 struct GNUNET_GNSRECORD_PluginFunctions *api = lib_ret; 82 struct GNUNET_GNSRECORD_PluginFunctions *api = lib_ret;
84 struct Plugin *plugin; 83 struct Plugin *plugin;
85 84
86 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 85 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
87 "Loading block plugin `%s'\n", 86 "Loading block plugin `%s'\n",
88 library_name); 87 library_name);
89 plugin = GNUNET_new (struct Plugin); 88 plugin = GNUNET_new(struct Plugin);
90 plugin->api = api; 89 plugin->api = api;
91 plugin->library_name = GNUNET_strdup (library_name); 90 plugin->library_name = GNUNET_strdup(library_name);
92 GNUNET_array_append (gns_plugins, num_plugins, plugin); 91 GNUNET_array_append(gns_plugins, num_plugins, plugin);
93} 92}
94 93
95 94
@@ -97,13 +96,13 @@ add_plugin (void *cls,
97 * Loads all plugins (lazy initialization). 96 * Loads all plugins (lazy initialization).
98 */ 97 */
99static void 98static void
100init () 99init()
101{ 100{
102 if (1 == once) 101 if (1 == once)
103 return; 102 return;
104 once = 1; 103 once = 1;
105 GNUNET_PLUGIN_load_all ("libgnunet_plugin_gnsrecord_", NULL, 104 GNUNET_PLUGIN_load_all("libgnunet_plugin_gnsrecord_", NULL,
106 &add_plugin, NULL); 105 &add_plugin, NULL);
107} 106}
108 107
109 108
@@ -111,20 +110,20 @@ init ()
111 * Dual function to #init(). 110 * Dual function to #init().
112 */ 111 */
113void __attribute__ ((destructor)) 112void __attribute__ ((destructor))
114GNSRECORD_fini () 113GNSRECORD_fini()
115{ 114{
116 struct Plugin *plugin; 115 struct Plugin *plugin;
117 116
118 for (unsigned int i = 0; i < num_plugins; i++) 117 for (unsigned int i = 0; i < num_plugins; i++)
119 { 118 {
120 plugin = gns_plugins[i]; 119 plugin = gns_plugins[i];
121 GNUNET_break (NULL == 120 GNUNET_break(NULL ==
122 GNUNET_PLUGIN_unload (plugin->library_name, 121 GNUNET_PLUGIN_unload(plugin->library_name,
123 plugin->api)); 122 plugin->api));
124 GNUNET_free (plugin->library_name); 123 GNUNET_free(plugin->library_name);
125 GNUNET_free (plugin); 124 GNUNET_free(plugin);
126 } 125 }
127 GNUNET_free_non_null (gns_plugins); 126 GNUNET_free_non_null(gns_plugins);
128 gns_plugins = NULL; 127 gns_plugins = NULL;
129 once = 0; 128 once = 0;
130 num_plugins = 0; 129 num_plugins = 0;
@@ -140,23 +139,23 @@ GNSRECORD_fini ()
140 * @return NULL on error, otherwise human-readable representation of the value 139 * @return NULL on error, otherwise human-readable representation of the value
141 */ 140 */
142char * 141char *
143GNUNET_GNSRECORD_value_to_string (uint32_t type, 142GNUNET_GNSRECORD_value_to_string(uint32_t type,
144 const void *data, 143 const void *data,
145 size_t data_size) 144 size_t data_size)
146{ 145{
147 struct Plugin *plugin; 146 struct Plugin *plugin;
148 char *ret; 147 char *ret;
149 148
150 init (); 149 init();
151 for (unsigned int i = 0; i < num_plugins; i++) 150 for (unsigned int i = 0; i < num_plugins; i++)
152 { 151 {
153 plugin = gns_plugins[i]; 152 plugin = gns_plugins[i];
154 if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls, 153 if (NULL != (ret = plugin->api->value_to_string(plugin->api->cls,
155 type, 154 type,
156 data, 155 data,
157 data_size))) 156 data_size)))
158 return ret; 157 return ret;
159 } 158 }
160 return NULL; 159 return NULL;
161} 160}
162 161
@@ -172,24 +171,24 @@ GNUNET_GNSRECORD_value_to_string (uint32_t type,
172 * @return #GNUNET_OK on success 171 * @return #GNUNET_OK on success
173 */ 172 */
174int 173int
175GNUNET_GNSRECORD_string_to_value (uint32_t type, 174GNUNET_GNSRECORD_string_to_value(uint32_t type,
176 const char *s, 175 const char *s,
177 void **data, 176 void **data,
178 size_t *data_size) 177 size_t *data_size)
179{ 178{
180 struct Plugin *plugin; 179 struct Plugin *plugin;
181 180
182 init (); 181 init();
183 for (unsigned int i = 0; i < num_plugins; i++) 182 for (unsigned int i = 0; i < num_plugins; i++)
184 { 183 {
185 plugin = gns_plugins[i]; 184 plugin = gns_plugins[i];
186 if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls, 185 if (GNUNET_OK == plugin->api->string_to_value(plugin->api->cls,
187 type, 186 type,
188 s, 187 s,
189 data, 188 data,
190 data_size)) 189 data_size))
191 return GNUNET_OK; 190 return GNUNET_OK;
192 } 191 }
193 return GNUNET_SYSERR; 192 return GNUNET_SYSERR;
194} 193}
195 194
@@ -201,22 +200,22 @@ GNUNET_GNSRECORD_string_to_value (uint32_t type,
201 * @return corresponding number, UINT32_MAX on error 200 * @return corresponding number, UINT32_MAX on error
202 */ 201 */
203uint32_t 202uint32_t
204GNUNET_GNSRECORD_typename_to_number (const char *dns_typename) 203GNUNET_GNSRECORD_typename_to_number(const char *dns_typename)
205{ 204{
206 struct Plugin *plugin; 205 struct Plugin *plugin;
207 uint32_t ret; 206 uint32_t ret;
208 207
209 if (0 == strcasecmp (dns_typename, 208 if (0 == strcasecmp(dns_typename,
210 "ANY")) 209 "ANY"))
211 return GNUNET_GNSRECORD_TYPE_ANY; 210 return GNUNET_GNSRECORD_TYPE_ANY;
212 init (); 211 init();
213 for (unsigned int i = 0; i < num_plugins; i++) 212 for (unsigned int i = 0; i < num_plugins; i++)
214 { 213 {
215 plugin = gns_plugins[i]; 214 plugin = gns_plugins[i];
216 if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls, 215 if (UINT32_MAX != (ret = plugin->api->typename_to_number(plugin->api->cls,
217 dns_typename))) 216 dns_typename)))
218 return ret; 217 return ret;
219 } 218 }
220 return UINT32_MAX; 219 return UINT32_MAX;
221} 220}
222 221
@@ -228,21 +227,21 @@ GNUNET_GNSRECORD_typename_to_number (const char *dns_typename)
228 * @return corresponding typestring, NULL on error 227 * @return corresponding typestring, NULL on error
229 */ 228 */
230const char * 229const char *
231GNUNET_GNSRECORD_number_to_typename (uint32_t type) 230GNUNET_GNSRECORD_number_to_typename(uint32_t type)
232{ 231{
233 struct Plugin *plugin; 232 struct Plugin *plugin;
234 const char * ret; 233 const char * ret;
235 234
236 if (GNUNET_GNSRECORD_TYPE_ANY == type) 235 if (GNUNET_GNSRECORD_TYPE_ANY == type)
237 return "ANY"; 236 return "ANY";
238 init (); 237 init();
239 for (unsigned int i = 0; i < num_plugins; i++) 238 for (unsigned int i = 0; i < num_plugins; i++)
240 { 239 {
241 plugin = gns_plugins[i]; 240 plugin = gns_plugins[i];
242 if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls, 241 if (NULL != (ret = plugin->api->number_to_typename(plugin->api->cls,
243 type))) 242 type)))
244 return ret; 243 return ret;
245 } 244 }
246 return NULL; 245 return NULL;
247} 246}
248 247