LCOV - code coverage report
Current view: top level - wire - wire.c (source / functions) Hit Total Coverage
Test: rcoverage.info Lines: 26 28 92.9 %
Date: 2017-11-25 11:31:41 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   (C) 2015, 2016, 2017 GNUnet e.V.
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify it under the
       6             :   terms of the GNU General Public License as published by the Free Software
       7             :   Foundation; either version 3, or (at your option) any later version.
       8             : 
       9             :   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
      10             :   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
      11             :   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
      12             : 
      13             :   You should have received a copy of the GNU General Public License along with
      14             :   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
      15             : */
      16             : 
      17             : /**
      18             :  * @file wire/wire.c
      19             :  * @brief Functions for loading wire plugins
      20             :  * @author Christian Grothoff <christian@grothoff.org>
      21             :  */
      22             : #include "platform.h"
      23             : #include "taler_util.h"
      24             : #include "taler_wire_lib.h"
      25             : 
      26             : /**
      27             :  * Load a WIRE plugin.
      28             :  *
      29             :  * @param cfg configuration to use
      30             :  * @param plugin_name name of the plugin to load
      31             :  * @return #GNUNET_OK on success
      32             :  */
      33             : struct TALER_WIRE_Plugin *
      34          27 : TALER_WIRE_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg,
      35             :                         const char *plugin_name)
      36             : {
      37             :   char *lib_name;
      38             :   struct TALER_WIRE_Plugin *plugin;
      39             : 
      40          27 :   (void) GNUNET_asprintf (&lib_name,
      41             :                           "libtaler_plugin_wire_%s",
      42             :                           plugin_name);
      43          27 :   plugin = GNUNET_PLUGIN_load (lib_name,
      44             :                                (void *) cfg);
      45          27 :   if (NULL != plugin)
      46          27 :     plugin->library_name = lib_name;
      47             :   else
      48           0 :     GNUNET_free (lib_name);
      49          27 :   return plugin;
      50             : }
      51             : 
      52             : 
      53             : /**
      54             :  * Unload a WIRE plugin.
      55             :  *
      56             :  * @param plugin the plugin to unload
      57             :  */
      58             : void
      59          26 : TALER_WIRE_plugin_unload (struct TALER_WIRE_Plugin *plugin)
      60             : {
      61             :   char *lib_name;
      62             : 
      63          26 :   if (NULL == plugin)
      64           0 :     return;
      65          26 :   lib_name = plugin->library_name;
      66          26 :   GNUNET_assert (NULL == GNUNET_PLUGIN_unload (lib_name,
      67             :                                                plugin));
      68          26 :   GNUNET_free (lib_name);
      69             : }
      70             : 
      71             : 
      72             : /**
      73             :  * Closure of #check_for_wire.
      74             :  */
      75             : struct FindEnabledWireContext
      76             : {
      77             :   /**
      78             :    * Configuration we are usign.
      79             :    */
      80             :   const struct GNUNET_CONFIGURATION_Handle *cfg;
      81             : 
      82             :   /**
      83             :    * Callback to invoke.
      84             :    */
      85             :   TALER_WIRE_EnabledCallback cb;
      86             : 
      87             :   /**
      88             :    * Closure for @e cb.
      89             :    */
      90             :   void *cb_cls;
      91             : };
      92             : 
      93             : 
      94             : /**
      95             :  * Check if @a section begins with "exchange-wire-", and if
      96             :  * so if the "ENABLE" option is set to "YES".  If both are
      97             :  * true, call the callback from the context with the
      98             :  * rest of the section name.
      99             :  *
     100             :  * @param cls our `struct FindEnabledWireContext`
     101             :  * @param section name of a section in the configuration
     102             :  */
     103             : static void
     104         249 : check_for_wire (void *cls,
     105             :                 const char *section)
     106             : {
     107         249 :   struct FindEnabledWireContext *ctx = cls;
     108             :   const char *name;
     109             : 
     110         249 :   if (0 != strncasecmp (section,
     111             :                         "exchange-wire-",
     112             :                         strlen ("exchange-wire-")))
     113         227 :     return;
     114          22 :   if (GNUNET_YES !=
     115          22 :       GNUNET_CONFIGURATION_get_value_yesno (ctx->cfg,
     116             :                                             section,
     117             :                                             "ENABLE"))
     118           4 :     return;
     119          18 :   name = &section[strlen ("exchange-wire-")];
     120          18 :   ctx->cb (ctx->cb_cls,
     121             :            name);
     122             : }
     123             : 
     124             : 
     125             : /**
     126             :  * Check which wire plugins are enabled in @a cfg and call @a cb for each one.
     127             :  *
     128             :  * @param cfg configuration to use
     129             :  * @param cb callback to invoke
     130             :  * @param cb_cls closure for @a cb
     131             :  */
     132             : void
     133          11 : TALER_WIRE_find_enabled (const struct GNUNET_CONFIGURATION_Handle *cfg,
     134             :                          TALER_WIRE_EnabledCallback cb,
     135             :                          void *cb_cls)
     136             : {
     137             :   struct FindEnabledWireContext ctx;
     138             : 
     139          11 :   ctx.cfg = cfg;
     140          11 :   ctx.cb = cb;
     141          11 :   ctx.cb_cls = cb_cls;
     142          11 :   GNUNET_CONFIGURATION_iterate_sections (cfg,
     143             :                                          &check_for_wire,
     144             :                                          &ctx);
     145          11 : }
     146             : 
     147             : 
     148             : /* end of wire.c */

Generated by: LCOV version 1.13