diff options
Diffstat (limited to 'src/gnsrecord/gnsrecord.c')
-rw-r--r-- | src/gnsrecord/gnsrecord.c | 137 |
1 files changed, 69 insertions, 68 deletions
diff --git a/src/gnsrecord/gnsrecord.c b/src/gnsrecord/gnsrecord.c index 7672a7b00..9d01210be 100644 --- a/src/gnsrecord/gnsrecord.c +++ b/src/gnsrecord/gnsrecord.c | |||
@@ -32,13 +32,14 @@ | |||
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 | */ |
41 | struct Plugin { | 41 | struct Plugin |
42 | { | ||
42 | /** | 43 | /** |
43 | * Name of the shared library. | 44 | * Name of the shared library. |
44 | */ | 45 | */ |
@@ -75,20 +76,20 @@ static int once; | |||
75 | * @param lib_ret the plugin API | 76 | * @param lib_ret the plugin API |
76 | */ | 77 | */ |
77 | static void | 78 | static void |
78 | add_plugin(void *cls, | 79 | add_plugin (void *cls, |
79 | const char *library_name, | 80 | const char *library_name, |
80 | void *lib_ret) | 81 | void *lib_ret) |
81 | { | 82 | { |
82 | struct GNUNET_GNSRECORD_PluginFunctions *api = lib_ret; | 83 | struct GNUNET_GNSRECORD_PluginFunctions *api = lib_ret; |
83 | struct Plugin *plugin; | 84 | struct Plugin *plugin; |
84 | 85 | ||
85 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 86 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
86 | "Loading block plugin `%s'\n", | 87 | "Loading block plugin `%s'\n", |
87 | library_name); | 88 | library_name); |
88 | plugin = GNUNET_new(struct Plugin); | 89 | plugin = GNUNET_new (struct Plugin); |
89 | plugin->api = api; | 90 | plugin->api = api; |
90 | plugin->library_name = GNUNET_strdup(library_name); | 91 | plugin->library_name = GNUNET_strdup (library_name); |
91 | GNUNET_array_append(gns_plugins, num_plugins, plugin); | 92 | GNUNET_array_append (gns_plugins, num_plugins, plugin); |
92 | } | 93 | } |
93 | 94 | ||
94 | 95 | ||
@@ -96,13 +97,13 @@ add_plugin(void *cls, | |||
96 | * Loads all plugins (lazy initialization). | 97 | * Loads all plugins (lazy initialization). |
97 | */ | 98 | */ |
98 | static void | 99 | static void |
99 | init() | 100 | init () |
100 | { | 101 | { |
101 | if (1 == once) | 102 | if (1 == once) |
102 | return; | 103 | return; |
103 | once = 1; | 104 | once = 1; |
104 | GNUNET_PLUGIN_load_all("libgnunet_plugin_gnsrecord_", NULL, | 105 | GNUNET_PLUGIN_load_all ("libgnunet_plugin_gnsrecord_", NULL, |
105 | &add_plugin, NULL); | 106 | &add_plugin, NULL); |
106 | } | 107 | } |
107 | 108 | ||
108 | 109 | ||
@@ -110,20 +111,20 @@ init() | |||
110 | * Dual function to #init(). | 111 | * Dual function to #init(). |
111 | */ | 112 | */ |
112 | void __attribute__ ((destructor)) | 113 | void __attribute__ ((destructor)) |
113 | GNSRECORD_fini() | 114 | GNSRECORD_fini () |
114 | { | 115 | { |
115 | struct Plugin *plugin; | 116 | struct Plugin *plugin; |
116 | 117 | ||
117 | for (unsigned int i = 0; i < num_plugins; i++) | 118 | for (unsigned int i = 0; i < num_plugins; i++) |
118 | { | 119 | { |
119 | plugin = gns_plugins[i]; | 120 | plugin = gns_plugins[i]; |
120 | GNUNET_break(NULL == | 121 | GNUNET_break (NULL == |
121 | GNUNET_PLUGIN_unload(plugin->library_name, | 122 | GNUNET_PLUGIN_unload (plugin->library_name, |
122 | plugin->api)); | 123 | plugin->api)); |
123 | GNUNET_free(plugin->library_name); | 124 | GNUNET_free (plugin->library_name); |
124 | GNUNET_free(plugin); | 125 | GNUNET_free (plugin); |
125 | } | 126 | } |
126 | GNUNET_free_non_null(gns_plugins); | 127 | GNUNET_free_non_null (gns_plugins); |
127 | gns_plugins = NULL; | 128 | gns_plugins = NULL; |
128 | once = 0; | 129 | once = 0; |
129 | num_plugins = 0; | 130 | num_plugins = 0; |
@@ -139,23 +140,23 @@ GNSRECORD_fini() | |||
139 | * @return NULL on error, otherwise human-readable representation of the value | 140 | * @return NULL on error, otherwise human-readable representation of the value |
140 | */ | 141 | */ |
141 | char * | 142 | char * |
142 | GNUNET_GNSRECORD_value_to_string(uint32_t type, | 143 | GNUNET_GNSRECORD_value_to_string (uint32_t type, |
143 | const void *data, | 144 | const void *data, |
144 | size_t data_size) | 145 | size_t data_size) |
145 | { | 146 | { |
146 | struct Plugin *plugin; | 147 | struct Plugin *plugin; |
147 | char *ret; | 148 | char *ret; |
148 | 149 | ||
149 | init(); | 150 | init (); |
150 | for (unsigned int i = 0; i < num_plugins; i++) | 151 | for (unsigned int i = 0; i < num_plugins; i++) |
151 | { | 152 | { |
152 | plugin = gns_plugins[i]; | 153 | plugin = gns_plugins[i]; |
153 | if (NULL != (ret = plugin->api->value_to_string(plugin->api->cls, | 154 | if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls, |
154 | type, | 155 | type, |
155 | data, | 156 | data, |
156 | data_size))) | 157 | data_size))) |
157 | return ret; | 158 | return ret; |
158 | } | 159 | } |
159 | return NULL; | 160 | return NULL; |
160 | } | 161 | } |
161 | 162 | ||
@@ -171,24 +172,24 @@ GNUNET_GNSRECORD_value_to_string(uint32_t type, | |||
171 | * @return #GNUNET_OK on success | 172 | * @return #GNUNET_OK on success |
172 | */ | 173 | */ |
173 | int | 174 | int |
174 | GNUNET_GNSRECORD_string_to_value(uint32_t type, | 175 | GNUNET_GNSRECORD_string_to_value (uint32_t type, |
175 | const char *s, | 176 | const char *s, |
176 | void **data, | 177 | void **data, |
177 | size_t *data_size) | 178 | size_t *data_size) |
178 | { | 179 | { |
179 | struct Plugin *plugin; | 180 | struct Plugin *plugin; |
180 | 181 | ||
181 | init(); | 182 | init (); |
182 | for (unsigned int i = 0; i < num_plugins; i++) | 183 | for (unsigned int i = 0; i < num_plugins; i++) |
183 | { | 184 | { |
184 | plugin = gns_plugins[i]; | 185 | plugin = gns_plugins[i]; |
185 | if (GNUNET_OK == plugin->api->string_to_value(plugin->api->cls, | 186 | if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls, |
186 | type, | 187 | type, |
187 | s, | 188 | s, |
188 | data, | 189 | data, |
189 | data_size)) | 190 | data_size)) |
190 | return GNUNET_OK; | 191 | return GNUNET_OK; |
191 | } | 192 | } |
192 | return GNUNET_SYSERR; | 193 | return GNUNET_SYSERR; |
193 | } | 194 | } |
194 | 195 | ||
@@ -200,22 +201,22 @@ GNUNET_GNSRECORD_string_to_value(uint32_t type, | |||
200 | * @return corresponding number, UINT32_MAX on error | 201 | * @return corresponding number, UINT32_MAX on error |
201 | */ | 202 | */ |
202 | uint32_t | 203 | uint32_t |
203 | GNUNET_GNSRECORD_typename_to_number(const char *dns_typename) | 204 | GNUNET_GNSRECORD_typename_to_number (const char *dns_typename) |
204 | { | 205 | { |
205 | struct Plugin *plugin; | 206 | struct Plugin *plugin; |
206 | uint32_t ret; | 207 | uint32_t ret; |
207 | 208 | ||
208 | if (0 == strcasecmp(dns_typename, | 209 | if (0 == strcasecmp (dns_typename, |
209 | "ANY")) | 210 | "ANY")) |
210 | return GNUNET_GNSRECORD_TYPE_ANY; | 211 | return GNUNET_GNSRECORD_TYPE_ANY; |
211 | init(); | 212 | init (); |
212 | for (unsigned int i = 0; i < num_plugins; i++) | 213 | for (unsigned int i = 0; i < num_plugins; i++) |
213 | { | 214 | { |
214 | plugin = gns_plugins[i]; | 215 | plugin = gns_plugins[i]; |
215 | if (UINT32_MAX != (ret = plugin->api->typename_to_number(plugin->api->cls, | 216 | if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls, |
216 | dns_typename))) | 217 | dns_typename))) |
217 | return ret; | 218 | return ret; |
218 | } | 219 | } |
219 | return UINT32_MAX; | 220 | return UINT32_MAX; |
220 | } | 221 | } |
221 | 222 | ||
@@ -227,21 +228,21 @@ GNUNET_GNSRECORD_typename_to_number(const char *dns_typename) | |||
227 | * @return corresponding typestring, NULL on error | 228 | * @return corresponding typestring, NULL on error |
228 | */ | 229 | */ |
229 | const char * | 230 | const char * |
230 | GNUNET_GNSRECORD_number_to_typename(uint32_t type) | 231 | GNUNET_GNSRECORD_number_to_typename (uint32_t type) |
231 | { | 232 | { |
232 | struct Plugin *plugin; | 233 | struct Plugin *plugin; |
233 | const char * ret; | 234 | const char *ret; |
234 | 235 | ||
235 | if (GNUNET_GNSRECORD_TYPE_ANY == type) | 236 | if (GNUNET_GNSRECORD_TYPE_ANY == type) |
236 | return "ANY"; | 237 | return "ANY"; |
237 | init(); | 238 | init (); |
238 | for (unsigned int i = 0; i < num_plugins; i++) | 239 | for (unsigned int i = 0; i < num_plugins; i++) |
239 | { | 240 | { |
240 | plugin = gns_plugins[i]; | 241 | plugin = gns_plugins[i]; |
241 | if (NULL != (ret = plugin->api->number_to_typename(plugin->api->cls, | 242 | if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls, |
242 | type))) | 243 | type))) |
243 | return ret; | 244 | return ret; |
244 | } | 245 | } |
245 | return NULL; | 246 | return NULL; |
246 | } | 247 | } |
247 | 248 | ||