LCOV - code coverage report
Current view: top level - backenddb - merchantdb_plugin.c (source / functions) Hit Total Coverage
Test: rcoverage.info Lines: 31 44 70.5 %
Date: 2018-09-19 06:18:31 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2015, 2016 GNUnet e.V. and INRIA
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify it under the
       6             :   terms of the GNU Lesser 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             :  * @file merchantdb/merchantdb_plugin.c
      18             :  * @brief Logic to load database plugin
      19             :  * @author Christian Grothoff
      20             :  * @author Sree Harsha Totakura <sreeharsha@totakura.in>
      21             :  */
      22             : #include "platform.h"
      23             : #include <taler/taler_util.h>
      24             : #include "taler_merchantdb_plugin.h"
      25             : #include <ltdl.h>
      26             : 
      27             : 
      28             : /**
      29             :  * Initialize the plugin.
      30             :  *
      31             :  * @param cfg configuration to use
      32             :  * @return #GNUNET_OK on success
      33             :  */
      34             : struct TALER_MERCHANTDB_Plugin *
      35           7 : TALER_MERCHANTDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
      36             : {
      37             :   char *plugin_name;
      38             :   char *lib_name;
      39             :   struct GNUNET_CONFIGURATION_Handle *cfg_dup;
      40             :   struct TALER_MERCHANTDB_Plugin *plugin;
      41             : 
      42           7 :   if (GNUNET_SYSERR ==
      43           7 :       GNUNET_CONFIGURATION_get_value_string (cfg,
      44             :                                              "merchant",
      45             :                                              "db",
      46             :                                              &plugin_name))
      47             :   {
      48           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
      49             :                                "merchant",
      50             :                                "db");
      51           0 :     return NULL;
      52             :   }
      53           7 :   (void) GNUNET_asprintf (&lib_name,
      54             :                           "libtaler_plugin_merchantdb_%s",
      55             :                           plugin_name);
      56           7 :   GNUNET_free (plugin_name);
      57           7 :   cfg_dup = GNUNET_CONFIGURATION_dup (cfg);
      58           7 :   plugin = GNUNET_PLUGIN_load (lib_name, cfg_dup);
      59           7 :   if (NULL != plugin)
      60           7 :     plugin->library_name = lib_name;
      61             :   else
      62           0 :     GNUNET_free (lib_name);
      63           7 :   GNUNET_CONFIGURATION_destroy (cfg_dup);
      64           7 :   return plugin;
      65             : }
      66             : 
      67             : 
      68             : /**
      69             :  * Shutdown the plugin.
      70             :  *
      71             :  * @param plugin the plugin to unload
      72             :  */
      73             : void
      74           7 : TALER_MERCHANTDB_plugin_unload (struct TALER_MERCHANTDB_Plugin *plugin)
      75             : {
      76             :   char *lib_name;
      77             : 
      78           7 :   if (NULL == plugin)
      79           0 :     return;
      80           7 :   lib_name = plugin->library_name;
      81           7 :   GNUNET_assert (NULL == GNUNET_PLUGIN_unload (lib_name,
      82             :                                                plugin));
      83           7 :   GNUNET_free (lib_name);
      84             : }
      85             : 
      86             : 
      87             : /**
      88             :  * Libtool search path before we started.
      89             :  */
      90             : static char *old_dlsearchpath;
      91             : 
      92             : 
      93             : /**
      94             :  * Setup libtool paths.
      95             :  */
      96             : void __attribute__ ((constructor))
      97           9 : plugin_init ()
      98             : {
      99             :   int err;
     100             :   const char *opath;
     101             :   char *path;
     102             :   char *cpath;
     103             : 
     104           9 :   err = lt_dlinit ();
     105           9 :   if (err > 0)
     106             :   {
     107           0 :     FPRINTF (stderr,
     108             :              _("Initialization of plugin mechanism failed: %s!\n"),
     109             :              lt_dlerror ());
     110           0 :     return;
     111             :   }
     112           9 :   opath = lt_dlgetsearchpath ();
     113           9 :   if (NULL != opath)
     114           0 :     old_dlsearchpath = GNUNET_strdup (opath);
     115           9 :   path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR);
     116           9 :   if (NULL != path)
     117             :   {
     118           9 :     if (NULL != opath)
     119             :     {
     120           0 :       GNUNET_asprintf (&cpath, "%s:%s", opath, path);
     121           0 :       lt_dlsetsearchpath (cpath);
     122           0 :       GNUNET_free (path);
     123           0 :       GNUNET_free (cpath);
     124             :     }
     125             :     else
     126             :     {
     127           9 :       lt_dlsetsearchpath (path);
     128           9 :       GNUNET_free (path);
     129             :     }
     130             :   }
     131             : }
     132             : 
     133             : 
     134             : /**
     135             :  * Shutdown libtool.
     136             :  */
     137             : void __attribute__ ((destructor))
     138           9 : plugin_fini ()
     139             : {
     140           9 :   lt_dlsetsearchpath (old_dlsearchpath);
     141           9 :   if (NULL != old_dlsearchpath)
     142             :   {
     143           0 :     GNUNET_free (old_dlsearchpath);
     144           0 :     old_dlsearchpath = NULL;
     145             :   }
     146           9 :   lt_dlexit ();
     147           9 : }
     148             : 
     149             : 
     150             : /* end of merchantdb_plugin.c */

Generated by: LCOV version 1.13