aboutsummaryrefslogtreecommitdiff
path: root/src/block/block.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/block/block.c')
-rw-r--r--src/block/block.c83
1 files changed, 41 insertions, 42 deletions
diff --git a/src/block/block.c b/src/block/block.c
index 8efb0d477..582c13eb3 100644
--- a/src/block/block.c
+++ b/src/block/block.c
@@ -54,11 +54,16 @@ struct Plugin
54struct GNUNET_BLOCK_Context 54struct GNUNET_BLOCK_Context
55{ 55{
56 /** 56 /**
57 * NULL-terminated array of our plugins. 57 * Array of our plugins.
58 */ 58 */
59 struct Plugin **plugins; 59 struct Plugin **plugins;
60 60
61 /** 61 /**
62 * Size of the 'plugins' array.
63 */
64 unsigned int num_plugins;
65
66 /**
62 * Our configuration. 67 * Our configuration.
63 */ 68 */
64 const struct GNUNET_CONFIGURATION_Handle *cfg; 69 const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -84,6 +89,33 @@ GNUNET_BLOCK_mingle_hash (const GNUNET_HashCode * in, uint32_t mingle_number,
84 89
85 90
86/** 91/**
92 * Add a plugin to the list managed by the block library.
93 *
94 * @param cls the block context
95 * @param library_name name of the plugin
96 * @param lib_ret the plugin API
97 */
98static void
99add_plugin (void *cls,
100 const char *library_name,
101 void *lib_ret)
102{
103 struct GNUNET_BLOCK_Context *ctx = cls;
104 struct GNUNET_BLOCK_PluginFunctions *api = lib_ret;
105 struct Plugin *plugin;
106
107 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
108 _("Loading block plugin `%s'\n"),
109 library_name);
110 plugin = GNUNET_malloc (sizeof (struct Plugin));
111 plugin->api = api;
112 plugin->library_name = GNUNET_strdup (library_name);
113 GNUNET_array_append (ctx->plugins, ctx->num_plugins, plugin);
114}
115
116
117
118/**
87 * Create a block context. Loads the block plugins. 119 * Create a block context. Loads the block plugins.
88 * 120 *
89 * @param cfg configuration to use 121 * @param cfg configuration to use
@@ -93,44 +125,13 @@ struct GNUNET_BLOCK_Context *
93GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg) 125GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg)
94{ 126{
95 struct GNUNET_BLOCK_Context *ctx; 127 struct GNUNET_BLOCK_Context *ctx;
96 struct GNUNET_BLOCK_PluginFunctions *api;
97 struct Plugin *plugin;
98 unsigned int num_plugins;
99 char *plugs;
100 char *pos;
101 char *libname;
102 128
103 ctx = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_Context)); 129 ctx = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_Context));
104 ctx->cfg = cfg; 130 ctx->cfg = cfg;
105 num_plugins = 0; 131 GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_",
106 if (GNUNET_OK == 132 NULL,
107 GNUNET_CONFIGURATION_get_value_string (cfg, "block", "PLUGINS", &plugs)) 133 &add_plugin,
108 { 134 ctx);
109 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading block plugins `%s'\n"),
110 plugs);
111 pos = strtok (plugs, " ");
112 while (pos != NULL)
113 {
114 GNUNET_asprintf (&libname, "libgnunet_plugin_block_%s", pos);
115 api = GNUNET_PLUGIN_load (libname, NULL);
116 if (api == NULL)
117 {
118 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
119 _("Failed to load block plugin `%s'\n"), pos);
120 GNUNET_free (libname);
121 }
122 else
123 {
124 plugin = GNUNET_malloc (sizeof (struct Plugin));
125 plugin->api = api;
126 plugin->library_name = libname;
127 GNUNET_array_append (ctx->plugins, num_plugins, plugin);
128 }
129 pos = strtok (NULL, " ");
130 }
131 GNUNET_free (plugs);
132 }
133 GNUNET_array_append (ctx->plugins, num_plugins, NULL);
134 return ctx; 135 return ctx;
135} 136}
136 137
@@ -146,14 +147,13 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx)
146 unsigned int i; 147 unsigned int i;
147 struct Plugin *plugin; 148 struct Plugin *plugin;
148 149
149 i = 0; 150 for (i = 0; i<ctx->num_plugins;i++)
150 while (NULL != (plugin = ctx->plugins[i]))
151 { 151 {
152 plugin = ctx->plugins[i];
152 GNUNET_break (NULL == 153 GNUNET_break (NULL ==
153 GNUNET_PLUGIN_unload (plugin->library_name, plugin->api)); 154 GNUNET_PLUGIN_unload (plugin->library_name, plugin->api));
154 GNUNET_free (plugin->library_name); 155 GNUNET_free (plugin->library_name);
155 GNUNET_free (plugin); 156 GNUNET_free (plugin);
156 i++;
157 } 157 }
158 GNUNET_free (ctx->plugins); 158 GNUNET_free (ctx->plugins);
159 GNUNET_free (ctx); 159 GNUNET_free (ctx);
@@ -174,9 +174,9 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type)
174 unsigned int i; 174 unsigned int i;
175 unsigned int j; 175 unsigned int j;
176 176
177 i = 0; 177 for (i=0;i<ctx->num_plugins;i++)
178 while (NULL != (plugin = ctx->plugins[i]))
179 { 178 {
179 plugin = ctx->plugins[i];
180 j = 0; 180 j = 0;
181 while (0 != (plugin->api->types[j])) 181 while (0 != (plugin->api->types[j]))
182 { 182 {
@@ -184,7 +184,6 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type)
184 return plugin->api; 184 return plugin->api;
185 j++; 185 j++;
186 } 186 }
187 i++;
188 } 187 }
189 return NULL; 188 return NULL;
190} 189}