LCOV - code coverage report
Current view: top level - backenddb - merchantdb_plugin.c (source / functions) Hit Total Coverage
Test: GNU Taler coverage report Lines: 0 43 0.0 %
Date: 2021-04-12 06:04:58 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14