aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo-tool/gnunet-peerinfo_plugins.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/peerinfo-tool/gnunet-peerinfo_plugins.c')
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo_plugins.c117
1 files changed, 58 insertions, 59 deletions
diff --git a/src/peerinfo-tool/gnunet-peerinfo_plugins.c b/src/peerinfo-tool/gnunet-peerinfo_plugins.c
index a8f43a1f1..13730629e 100644
--- a/src/peerinfo-tool/gnunet-peerinfo_plugins.c
+++ b/src/peerinfo-tool/gnunet-peerinfo_plugins.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file peerinfo-tool/gnunet-peerinfo_plugins.c 22 * @file peerinfo-tool/gnunet-peerinfo_plugins.c
@@ -31,8 +31,7 @@
31/** 31/**
32 * Entry in doubly-linked list of all of our plugins. 32 * Entry in doubly-linked list of all of our plugins.
33 */ 33 */
34struct TransportPlugin 34struct TransportPlugin {
35{
36 /** 35 /**
37 * This is a doubly-linked list. 36 * This is a doubly-linked list.
38 */ 37 */
@@ -64,7 +63,6 @@ struct TransportPlugin
64 * for this plugin. 63 * for this plugin.
65 */ 64 */
66 struct GNUNET_TRANSPORT_PluginEnvironment env; 65 struct GNUNET_TRANSPORT_PluginEnvironment env;
67
68}; 66};
69 67
70/** 68/**
@@ -88,7 +86,7 @@ static struct TransportPlugin *plugins_tail;
88 * @param cfg configuration to use 86 * @param cfg configuration to use
89 */ 87 */
90void 88void
91GPI_plugins_load (const struct GNUNET_CONFIGURATION_Handle *cfg) 89GPI_plugins_load(const struct GNUNET_CONFIGURATION_Handle *cfg)
92{ 90{
93 struct TransportPlugin *plug; 91 struct TransportPlugin *plug;
94 struct TransportPlugin *next; 92 struct TransportPlugin *next;
@@ -99,41 +97,41 @@ GPI_plugins_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
99 if (NULL != plugins_head) 97 if (NULL != plugins_head)
100 return; /* already loaded */ 98 return; /* already loaded */
101 if (GNUNET_OK != 99 if (GNUNET_OK !=
102 GNUNET_CONFIGURATION_get_value_string (cfg, "TRANSPORT", "PLUGINS", 100 GNUNET_CONFIGURATION_get_value_string(cfg, "TRANSPORT", "PLUGINS",
103 &plugs)) 101 &plugs))
104 return; 102 return;
105 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting transport plugins `%s'\n"), 103 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Starting transport plugins `%s'\n"),
106 plugs); 104 plugs);
107 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " ")) 105 for (pos = strtok(plugs, " "); pos != NULL; pos = strtok(NULL, " "))
108 { 106 {
109 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' transport plugin\n"), 107 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Loading `%s' transport plugin\n"),
110 pos); 108 pos);
111 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", pos); 109 GNUNET_asprintf(&libname, "libgnunet_plugin_transport_%s", pos);
112 plug = GNUNET_new (struct TransportPlugin); 110 plug = GNUNET_new(struct TransportPlugin);
113 plug->short_name = GNUNET_strdup (pos); 111 plug->short_name = GNUNET_strdup(pos);
114 plug->lib_name = libname; 112 plug->lib_name = libname;
115 plug->env.cfg = cfg; 113 plug->env.cfg = cfg;
116 plug->env.cls = plug->short_name; 114 plug->env.cls = plug->short_name;
117 GNUNET_CONTAINER_DLL_insert (plugins_head, plugins_tail, plug); 115 GNUNET_CONTAINER_DLL_insert(plugins_head, plugins_tail, plug);
118 } 116 }
119 GNUNET_free (plugs); 117 GNUNET_free(plugs);
120 next = plugins_head; 118 next = plugins_head;
121 while (next != NULL) 119 while (next != NULL)
122 {
123 plug = next;
124 next = plug->next;
125 plug->api = GNUNET_PLUGIN_load (plug->lib_name, &plug->env);
126 if (plug->api == NULL)
127 { 120 {
128 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 121 plug = next;
129 _("Failed to load transport plugin for `%s'\n"), 122 next = plug->next;
130 plug->lib_name); 123 plug->api = GNUNET_PLUGIN_load(plug->lib_name, &plug->env);
131 GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug); 124 if (plug->api == NULL)
132 GNUNET_free (plug->short_name); 125 {
133 GNUNET_free (plug->lib_name); 126 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
134 GNUNET_free (plug); 127 _("Failed to load transport plugin for `%s'\n"),
128 plug->lib_name);
129 GNUNET_CONTAINER_DLL_remove(plugins_head, plugins_tail, plug);
130 GNUNET_free(plug->short_name);
131 GNUNET_free(plug->lib_name);
132 GNUNET_free(plug);
133 }
135 } 134 }
136 }
137} 135}
138 136
139 137
@@ -141,18 +139,18 @@ GPI_plugins_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
141 * Unload all plugins 139 * Unload all plugins
142 */ 140 */
143void 141void
144GPI_plugins_unload () 142GPI_plugins_unload()
145{ 143{
146 struct TransportPlugin *plug; 144 struct TransportPlugin *plug;
147 145
148 while (NULL != (plug = plugins_head)) 146 while (NULL != (plug = plugins_head))
149 { 147 {
150 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api)); 148 GNUNET_break(NULL == GNUNET_PLUGIN_unload(plug->lib_name, plug->api));
151 GNUNET_free (plug->lib_name); 149 GNUNET_free(plug->lib_name);
152 GNUNET_free (plug->short_name); 150 GNUNET_free(plug->short_name);
153 GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug); 151 GNUNET_CONTAINER_DLL_remove(plugins_head, plugins_tail, plug);
154 GNUNET_free (plug); 152 GNUNET_free(plug);
155 } 153 }
156} 154}
157 155
158 156
@@ -163,31 +161,32 @@ GPI_plugins_unload ()
163 * @return the plugin's API, NULL if the plugin is not loaded 161 * @return the plugin's API, NULL if the plugin is not loaded
164 */ 162 */
165struct GNUNET_TRANSPORT_PluginFunctions * 163struct GNUNET_TRANSPORT_PluginFunctions *
166GPI_plugins_find (const char *name) 164GPI_plugins_find(const char *name)
167{ 165{
168 struct TransportPlugin *head = plugins_head; 166 struct TransportPlugin *head = plugins_head;
169 167
170 char *stripped = GNUNET_strdup (name); 168 char *stripped = GNUNET_strdup(name);
171 char *head_stripped; 169 char *head_stripped;
172 char *sep = strchr (stripped, '_'); 170 char *sep = strchr(stripped, '_');
171
173 if (NULL != sep) 172 if (NULL != sep)
174 sep[0] = '\0'; 173 sep[0] = '\0';
175 174
176 while (head != NULL) 175 while (head != NULL)
177 {
178 head_stripped = GNUNET_strdup(head->short_name);
179 char *head_sep = strchr (head_stripped, '_');
180 if (NULL != head_sep)
181 head_sep[0] = '\0';
182 if (0 == strcmp (head_stripped, stripped))
183 { 176 {
184 GNUNET_free (head_stripped); 177 head_stripped = GNUNET_strdup(head->short_name);
185 break; 178 char *head_sep = strchr(head_stripped, '_');
179 if (NULL != head_sep)
180 head_sep[0] = '\0';
181 if (0 == strcmp(head_stripped, stripped))
182 {
183 GNUNET_free(head_stripped);
184 break;
185 }
186 GNUNET_free(head_stripped);
187 head = head->next;
186 } 188 }
187 GNUNET_free (head_stripped); 189 GNUNET_free(stripped);
188 head = head->next;
189 }
190 GNUNET_free (stripped);
191 if (NULL == head) 190 if (NULL == head)
192 return NULL; 191 return NULL;
193 return head->api; 192 return head->api;