Example #1
0
static int
check ()
{
  void *ret;

  GNUNET_log_skip (1, GNUNET_NO);
  ret = GNUNET_PLUGIN_load ("libgnunet_plugin_missing", NULL);
  GNUNET_log_skip (0, GNUNET_NO);
  if (ret != NULL)
    return 1;
  ret = GNUNET_PLUGIN_load ("libgnunet_plugin_test", "in");
  if (ret == NULL)
    return 1;
  if (0 != strcmp (ret, "Hello"))
    return 2;
  ret = GNUNET_PLUGIN_unload ("libgnunet_plugin_test", "out");
  if (ret == NULL)
    return 3;
  if (0 != strcmp (ret, "World"))
    return 4;
  free (ret);

  GNUNET_PLUGIN_load_all ("libgnunet_plugin_tes", "in", &test_cb, "test");
  return 0;
}
Example #2
0
/**
 * Function called when the service shuts down.  Unloads our namestore
 * plugin.
 *
 * @param api api to unload
 */
static void
unload_plugin (struct GNUNET_NAMESTORE_PluginFunctions *api)
{
  char *libname;

  GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name);
  GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
  GNUNET_free (libname);
}
/**
 * Shutdown address subsystem.
 */
void
GAS_plugin_done ()
{
  GNUNET_PLUGIN_unload (plugin,
                        sf);
  sf = NULL;
  GNUNET_free (plugin);
  plugin = NULL;
}
Example #4
0
static void
test_cb (void *cls, const char *libname, void *lib_ret)
{
  void *ret;

  GNUNET_assert (0 == strcmp (cls, "test"));
  GNUNET_assert (0 == strcmp (lib_ret, "Hello"));
  ret = GNUNET_PLUGIN_unload (libname, "out");
  GNUNET_assert (NULL != ret);
  GNUNET_assert (0 == strcmp (ret, "World"));
}
/**
 * Unload all plugins
 */
void
GST_plugins_unload ()
{
    struct TransportPlugin *plug;

    while (NULL != (plug = plugins_head))
    {
        GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
        GNUNET_free (plug->lib_name);
        GNUNET_free (plug->short_name);
        GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug);
        GNUNET_free (plug);
    }
}
Example #6
0
/**
 * Destroy a data cache (and free associated resources).
 *
 * @param h handle to the datastore
 */
void
GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h)
{
  if (NULL != h->filter)
    GNUNET_CONTAINER_bloomfilter_free (h->filter);
  if (h->api != NULL)
    GNUNET_break (NULL == GNUNET_PLUGIN_unload (h->lib_name, h->api));
  GNUNET_free (h->lib_name);
  GNUNET_free (h->short_name);
  GNUNET_free (h->section);
  if (h->bloom_name != NULL)
  {
    if (0 != UNLINK (h->bloom_name))
      GNUNET_log_from_strerror_file (GNUNET_ERROR_TYPE_WARNING, "datacache",
                                     "unlink", h->bloom_name);
    GNUNET_free (h->bloom_name);
  }
  GNUNET_STATISTICS_destroy (h->stats, GNUNET_NO);
  GNUNET_free (h);
}
/**
 * Load and initialize all plugins.  The respective functions will be
 * invoked by the plugins when the respective events happen.  The
 * closure will be set to a 'const char*' containing the name of the
 * plugin that caused the call.
 *
 * @param recv_cb function to call when data is received
 * @param address_cb function to call when our public addresses changed
 * @param session_start_cb function to call when a session was created
 * @param session_end_cb function to call when a session was terminated
 * @param address_type_cb function to call when a address type is requested
 */
void
GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
                  GNUNET_TRANSPORT_AddressNotification address_cb,
                  GNUNET_TRANSPORT_SessionStart session_start_cb,
                  GNUNET_TRANSPORT_SessionEnd session_end_cb)
{
  struct TransportPlugin *plug;
  struct TransportPlugin *next;
  unsigned long long tneigh;
  char *libname;
  char *plugs;
  char *pos;
  int fail;

  if (GNUNET_OK !=
      GNUNET_CONFIGURATION_get_value_number (GST_cfg,
                                             "TRANSPORT",
                                             "NEIGHBOUR_LIMIT",
                                             &tneigh))
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Transport service is lacking NEIGHBOUR_LIMIT option.\n"));
    return;
  }
  if (GNUNET_OK !=
      GNUNET_CONFIGURATION_get_value_string (GST_cfg,
                                             "TRANSPORT",
                                             "PLUGINS",
                                             &plugs))
    return;
  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              _("Starting transport plugins `%s'\n"),
              plugs);
  for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
  {
    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                _("Loading `%s' transport plugin\n"),
                pos);
    GNUNET_asprintf (&libname,
                     "libgnunet_plugin_transport_%s",
                     pos);
    plug = GNUNET_new (struct TransportPlugin);
    plug->short_name = GNUNET_strdup (pos);
    plug->lib_name = libname;
    plug->env.cfg = GST_cfg;
    plug->env.my_identity = &GST_my_identity;
    plug->env.get_our_hello = &GST_hello_get;
    plug->env.cls = plug->short_name;
    plug->env.receive = recv_cb;
    plug->env.notify_address = address_cb;
    plug->env.session_start = session_start_cb;
    plug->env.session_end = session_end_cb;
    plug->env.get_address_type = &plugin_env_address_to_type;
    plug->env.update_address_distance = &plugin_env_update_distance;
    plug->env.max_connections = tneigh;
    plug->env.stats = GST_stats;
    GNUNET_CONTAINER_DLL_insert (plugins_head,
                                 plugins_tail,
                                 plug);
  }
  GNUNET_free (plugs);
  next = plugins_head;
  while (NULL != next)
  {
    plug = next;
    next = plug->next;
    plug->api = GNUNET_PLUGIN_load (plug->lib_name,
                                    &plug->env);
    if (NULL == plug->api)
    {
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Failed to load transport plugin for `%s'\n"),
                  plug->lib_name);
      GNUNET_CONTAINER_DLL_remove (plugins_head,
                                   plugins_tail,
                                   plug);
      GNUNET_free (plug->short_name);
      GNUNET_free (plug->lib_name);
      GNUNET_free (plug);
      continue;
    }
    fail = GNUNET_NO;
    if (NULL == plug->api->address_pretty_printer)
    {
    	fail = GNUNET_YES;
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Missing function `%s' in transport plugin for `%s'\n"),
                  "address_pretty_printer",
                  plug->lib_name);
    }
    if (NULL == plug->api->address_to_string)
    {
    	fail = GNUNET_YES;
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Missing function `%s' in transport plugin for `%s'\n"),
                  "address_to_string",
                  plug->lib_name);
    }
    if (NULL == plug->api->string_to_address)
    {
    	fail = GNUNET_YES;
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Missing function `%s' in transport plugin for `%s'\n"),
                  "string_to_address",
                  plug->lib_name);
    }
    if (NULL == plug->api->check_address)
    {
      fail = GNUNET_YES;
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Missing function `%s' in transport plugin for `%s'\n"),
                  "check_address",
                  plug->lib_name);
    }
    if (NULL == plug->api->get_session)
    {
      fail = GNUNET_YES;
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Missing function `%s' in transport plugin for `%s'\n"),
                  "get_session",
                  plug->lib_name);
    }
    if (NULL == plug->api->get_network)
    {
      fail = GNUNET_YES;
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Missing function `%s' in transport plugin for `%s'\n"),
                  "get_network",
                  plug->lib_name);
    }
    if (NULL == plug->api->send)
    {
      fail = GNUNET_YES;
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Missing function `%s' in transport plugin for `%s'\n"),
                  "send",
                  plug->lib_name);
    }
    if (NULL == plug->api->disconnect_peer)
    {
    	fail = GNUNET_YES;
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Missing function `%s' in transport plugin for `%s'\n"),
                  "disconnect_peer",
                  plug->lib_name);
    }
    if (NULL == plug->api->disconnect_session)
    {
    	fail = GNUNET_YES;
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Missing function `%s' in transport plugin for `%s'\n"),
                  "disconnect_session",
                  plug->lib_name);
    }
    if (NULL == plug->api->query_keepalive_factor)
    {
      fail = GNUNET_YES;
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Missing function `%s' in transport plugin for `%s'\n"),
                  "query_keepalive_factor",
                  plug->lib_name);
    }
    if (NULL == plug->api->update_session_timeout)
    {
        fail = GNUNET_YES;
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Missing function `%s' in transport plugin for `%s'\n"),
                  "update_session_timeout",
                  plug->lib_name);
    }
    if (GNUNET_YES == fail)
    {
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Did not load plugin `%s' due to missing functions\n"),
                  plug->lib_name);
      GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
      GNUNET_CONTAINER_DLL_remove (plugins_head,
                                   plugins_tail,
                                   plug);
      GNUNET_free (plug->short_name);
      GNUNET_free (plug->lib_name);
      GNUNET_free (plug);
    }
  }
}