2 This file is part of GNUnet.
3 (C) 2009-2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file gnsrecord/gnsrecord.c
23 * @brief API to access GNS record data
24 * @author Martin Schanzenbach
25 * @author Matthias Wachs
26 * @author Christian Grothoff
29 #include "gnunet_util_lib.h"
30 #include "gnunet_constants.h"
31 #include "gnunet_gnsrecord_lib.h"
32 #include "gnunet_gnsrecord_plugin.h"
33 #include "gnunet_tun_lib.h"
36 #define LOG(kind,...) GNUNET_log_from (kind, "gnsrecord",__VA_ARGS__)
40 * Handle for a plugin.
45 * Name of the shared library.
52 struct GNUNET_GNSRECORD_PluginFunctions *api;
57 * Array of our plugins.
59 static struct Plugin **plugins;
62 * Size of the 'plugins' array.
64 static unsigned int num_plugins;
67 * Global to mark if we've run the initialization.
73 * Add a plugin to the list managed by the block library.
76 * @param library_name name of the plugin
77 * @param lib_ret the plugin API
80 add_plugin (void *cls,
81 const char *library_name,
84 struct GNUNET_GNSRECORD_PluginFunctions *api = lib_ret;
85 struct Plugin *plugin;
87 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
88 "Loading block plugin `%s'\n",
90 plugin = GNUNET_new (struct Plugin);
92 plugin->library_name = GNUNET_strdup (library_name);
93 GNUNET_array_append (plugins, num_plugins, plugin);
98 * Loads all plugins (lazy initialization).
106 GNUNET_PLUGIN_load_all ("libgnunet_plugin_gnsrecord_", NULL,
112 * Dual function to #init().
114 void __attribute__ ((destructor))
118 struct Plugin *plugin;
120 for (i = 0; i < num_plugins; i++)
123 GNUNET_break (NULL ==
124 GNUNET_PLUGIN_unload (plugin->library_name,
126 GNUNET_free (plugin->library_name);
127 GNUNET_free (plugin);
129 GNUNET_free_non_null (plugins);
137 * Convert the 'value' of a record to a string.
139 * @param type type of the record
140 * @param data value in binary encoding
141 * @param data_size number of bytes in @a data
142 * @return NULL on error, otherwise human-readable representation of the value
145 GNUNET_GNSRECORD_value_to_string (uint32_t type,
150 struct Plugin *plugin;
154 for (i = 0; i < num_plugins; i++)
157 if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls,
168 * Convert human-readable version of a 'value' of a record to the binary
171 * @param type type of the record
172 * @param s human-readable string
173 * @param data set to value in binary encoding (will be allocated)
174 * @param data_size set to number of bytes in @a data
175 * @return #GNUNET_OK on success
178 GNUNET_GNSRECORD_string_to_value (uint32_t type,
184 struct Plugin *plugin;
187 for (i = 0; i < num_plugins; i++)
190 if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls,
197 return GNUNET_SYSERR;
202 * Convert a type name (i.e. "AAAA") to the corresponding number.
204 * @param dns_typename name to convert
205 * @return corresponding number, UINT32_MAX on error
208 GNUNET_GNSRECORD_typename_to_number (const char *dns_typename)
211 struct Plugin *plugin;
215 for (i = 0; i < num_plugins; i++)
218 if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls,
227 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
229 * @param type number of a type to convert
230 * @return corresponding typestring, NULL on error
233 GNUNET_GNSRECORD_number_to_typename (uint32_t type)
236 struct Plugin *plugin;
240 for (i = 0; i < num_plugins; i++)
243 if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls,
251 /* end of gnsrecord.c */