diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-09-21 12:15:48 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-09-21 12:15:48 +0000 |
commit | c67945ebea571b20777ead4663d2788ff8abb924 (patch) | |
tree | 2dd3bec42e1e3d2e61ab97338b62ebf26e867d59 /src/transport/gnunet-service-transport_plugins.c | |
parent | 23fbfdade60daf4b88cec374ccd4532d8c87324b (diff) | |
download | gnunet-c67945ebea571b20777ead4663d2788ff8abb924.tar.gz gnunet-c67945ebea571b20777ead4663d2788ff8abb924.zip |
prefix based plugin lookup for transport
Diffstat (limited to 'src/transport/gnunet-service-transport_plugins.c')
-rw-r--r-- | src/transport/gnunet-service-transport_plugins.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c index fc14b6e76..cabb676cd 100644 --- a/src/transport/gnunet-service-transport_plugins.c +++ b/src/transport/gnunet-service-transport_plugins.c | |||
@@ -197,6 +197,43 @@ GST_plugins_find (const char *name) | |||
197 | 197 | ||
198 | 198 | ||
199 | /** | 199 | /** |
200 | * Obtain the plugin API based on a the stripped plugin name after the underscore. | ||
201 | * | ||
202 | * Example: GST_plugins_printer_find (http_client) will return all plugins | ||
203 | * starting with the prefix "http": | ||
204 | * http_client or server if loaded | ||
205 | * | ||
206 | * @param name name of the plugin | ||
207 | * @return the plugin's API, NULL if the plugin is not loaded | ||
208 | */ | ||
209 | struct GNUNET_TRANSPORT_PluginFunctions * | ||
210 | GST_plugins_printer_find (const char *name) | ||
211 | { | ||
212 | struct TransportPlugin *head = plugins_head; | ||
213 | |||
214 | char *stripped = GNUNET_strdup (name); | ||
215 | char *sep = strchr (stripped, '_'); | ||
216 | if (NULL != sep) | ||
217 | sep[0] = '\0'; | ||
218 | |||
219 | while (head != NULL) | ||
220 | { | ||
221 | if (head->short_name == strstr (head->short_name, stripped)) | ||
222 | break; | ||
223 | head = head->next; | ||
224 | } | ||
225 | if (NULL != head) | ||
226 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
227 | "Found `%s' in '%s'\n", | ||
228 | stripped, head->short_name); | ||
229 | GNUNET_free (stripped); | ||
230 | if (NULL == head) | ||
231 | return NULL; | ||
232 | return head->api; | ||
233 | } | ||
234 | |||
235 | |||
236 | /** | ||
200 | * Convert a given address to a human-readable format. Note that the | 237 | * Convert a given address to a human-readable format. Note that the |
201 | * return value will be overwritten on the next call to this function. | 238 | * return value will be overwritten on the next call to this function. |
202 | * | 239 | * |
@@ -211,7 +248,7 @@ GST_plugins_a2s (const struct GNUNET_HELLO_Address *address) | |||
211 | 248 | ||
212 | if (address == NULL) | 249 | if (address == NULL) |
213 | return "<inbound>"; | 250 | return "<inbound>"; |
214 | api = GST_plugins_find (address->transport_name); | 251 | api = GST_plugins_printer_find (address->transport_name); |
215 | if (NULL == api) | 252 | if (NULL == api) |
216 | return "<plugin unknown>"; | 253 | return "<plugin unknown>"; |
217 | if (0 == address->address_length) | 254 | if (0 == address->address_length) |