LCOV - code coverage report
Current view: top level - backenddb - merchantdb_plugin.c (source / functions) Hit Total Coverage
Test: GNU Taler coverage report Lines: 24 42 57.1 %
Date: 2020-08-15 06:12:35 Functions: 3 4 75.0 %
Legend: Lines: hit not hit

          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[in,out] cfg configuration to use
      32             :  * @return #GNUNET_OK on success
      33             :  */
      34             : struct TALER_MERCHANTDB_Plugin *
      35           2 : TALER_MERCHANTDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
      36             : {
      37             :   char *plugin_name;
      38             :   char *lib_name;
      39             :   struct TALER_MERCHANTDB_Plugin *plugin;
      40             : 
      41           2 :   if (GNUNET_SYSERR ==
      42           2 :       GNUNET_CONFIGURATION_get_value_string (cfg,
      43             :                                              "merchant",
      44             :                                              "db",
      45             :                                              &plugin_name))
      46             :   {
      47           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
      48             :                                "merchant",
      49             :                                "db");
      50           0 :     return NULL;
      51             :   }
      52           2 :   (void) GNUNET_asprintf (&lib_name,
      53             :                           "libtaler_plugin_merchantdb_%s",
      54             :                           plugin_name);
      55           2 :   GNUNET_free (plugin_name);
      56           2 :   plugin = GNUNET_PLUGIN_load (lib_name,
      57             :                                (void *) cfg);
      58           2 :   if (NULL != plugin)
      59           0 :     plugin->library_name = lib_name;
      60             :   else
      61           2 :     GNUNET_free (lib_name);
      62           2 :   return plugin;
      63             : }
      64             : 
      65             : 
      66             : /**
      67             :  * Shutdown the plugin.
      68             :  *
      69             :  * @param plugin the plugin to unload
      70             :  */
      71             : void
      72           0 : TALER_MERCHANTDB_plugin_unload (struct TALER_MERCHANTDB_Plugin *plugin)
      73             : {
      74             :   char *lib_name;
      75             : 
      76           0 :   if (NULL == plugin)
      77           0 :     return;
      78           0 :   lib_name = plugin->library_name;
      79           0 :   GNUNET_assert (NULL == GNUNET_PLUGIN_unload (lib_name,
      80             :                                                plugin));
      81           0 :   GNUNET_free (lib_name);
      82             : }
      83             : 
      84             : 
      85             : /**
      86             :  * Libtool search path before we started.
      87             :  */
      88             : static char *old_dlsearchpath;
      89             : 
      90             : 
      91             : /**
      92             :  * Setup libtool paths.
      93             :  */
      94             : void __attribute__ ((constructor))
      95           2 : plugin_init ()
      96             : {
      97             :   int err;
      98             :   const char *opath;
      99             :   char *path;
     100             :   char *cpath;
     101             : 
     102           2 :   err = lt_dlinit ();
     103           2 :   if (err > 0)
     104             :   {
     105           0 :     fprintf (stderr,
     106             :              _ ("Initialization of plugin mechanism failed: %s!\n"),
     107             :              lt_dlerror ());
     108           0 :     return;
     109             :   }
     110           2 :   opath = lt_dlgetsearchpath ();
     111           2 :   if (NULL != opath)
     112           0 :     old_dlsearchpath = GNUNET_strdup (opath);
     113           2 :   path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR);
     114           2 :   if (NULL != path)
     115             :   {
     116           2 :     if (NULL != opath)
     117             :     {
     118           0 :       GNUNET_asprintf (&cpath, "%s:%s", opath, path);
     119           0 :       lt_dlsetsearchpath (cpath);
     120           0 :       GNUNET_free (path);
     121           0 :       GNUNET_free (cpath);
     122             :     }
     123             :     else
     124             :     {
     125           2 :       lt_dlsetsearchpath (path);
     126           2 :       GNUNET_free (path);
     127             :     }
     128             :   }
     129             : }
     130             : 
     131             : 
     132             : /**
     133             :  * Shutdown libtool.
     134             :  */
     135             : void __attribute__ ((destructor))
     136           2 : plugin_fini ()
     137             : {
     138           2 :   lt_dlsetsearchpath (old_dlsearchpath);
     139           2 :   if (NULL != old_dlsearchpath)
     140             :   {
     141           0 :     GNUNET_free (old_dlsearchpath);
     142           0 :     old_dlsearchpath = NULL;
     143             :   }
     144           2 :   lt_dlexit ();
     145           2 : }
     146             : 
     147             : 
     148             : /* end of merchantdb_plugin.c */

Generated by: LCOV version 1.14