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 | |
parent | 23fbfdade60daf4b88cec374ccd4532d8c87324b (diff) | |
download | gnunet-c67945ebea571b20777ead4663d2788ff8abb924.tar.gz gnunet-c67945ebea571b20777ead4663d2788ff8abb924.zip |
prefix based plugin lookup for transport
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/gnunet-service-transport_clients.c | 2 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_plugins.c | 39 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_plugins.h | 13 |
3 files changed, 52 insertions, 2 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 2d1db9b2f..294af9ba9 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -769,7 +769,7 @@ clients_handle_address_to_string (void *cls, | |||
769 | rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout); | 769 | rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout); |
770 | numeric = ntohs (alum->numeric_only); | 770 | numeric = ntohs (alum->numeric_only); |
771 | tc = GNUNET_SERVER_transmit_context_create (client); | 771 | tc = GNUNET_SERVER_transmit_context_create (client); |
772 | papi = GST_plugins_find (plugin_name); | 772 | papi = GST_plugins_printer_find (plugin_name); |
773 | if (NULL == papi) | 773 | if (NULL == papi) |
774 | { | 774 | { |
775 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 775 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
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) |
diff --git a/src/transport/gnunet-service-transport_plugins.h b/src/transport/gnunet-service-transport_plugins.h index 04bb5ea22..97e8f4c6f 100644 --- a/src/transport/gnunet-service-transport_plugins.h +++ b/src/transport/gnunet-service-transport_plugins.h | |||
@@ -66,6 +66,19 @@ GST_plugins_unload (void); | |||
66 | struct GNUNET_TRANSPORT_PluginFunctions * | 66 | struct GNUNET_TRANSPORT_PluginFunctions * |
67 | GST_plugins_find (const char *name); | 67 | GST_plugins_find (const char *name); |
68 | 68 | ||
69 | /** | ||
70 | * Obtain the plugin API based on a the stripped plugin name after the underscore. | ||
71 | * | ||
72 | * Example: GST_plugins_printer_find (http_client) will return all plugins | ||
73 | * starting with the prefix "http": | ||
74 | * http_client or server if loaded | ||
75 | * | ||
76 | * @param name name of the plugin | ||
77 | * @return the plugin's API, NULL if the plugin is not loaded | ||
78 | */ | ||
79 | struct GNUNET_TRANSPORT_PluginFunctions * | ||
80 | GST_plugins_printer_find (const char *name); | ||
81 | |||
69 | 82 | ||
70 | /** | 83 | /** |
71 | * Convert a given address to a human-readable format. Note that the | 84 | * Convert a given address to a human-readable format. Note that the |