LCOV - code coverage report
Current view: top level - syncdb - sync_db_plugin.c (source / functions) Hit Total Coverage
Test: GNU Taler sync coverage report Lines: 24 42 57.1 %
Date: 2022-08-25 06:17:07 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) 2019 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 syncdb/sync_db_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 "sync_database_plugin.h"
      24             : #include <ltdl.h>
      25             : 
      26             : 
      27             : /**
      28             :  * Initialize the plugin.
      29             :  *
      30             :  * @param cfg configuration to use
      31             :  * @return NULL on failure
      32             :  */
      33             : struct SYNC_DatabasePlugin *
      34           1 : SYNC_DB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
      35             : {
      36             :   char *plugin_name;
      37             :   char *lib_name;
      38             :   struct SYNC_DatabasePlugin *plugin;
      39             : 
      40           1 :   if (GNUNET_SYSERR ==
      41           1 :       GNUNET_CONFIGURATION_get_value_string (cfg,
      42             :                                              "sync",
      43             :                                              "db",
      44             :                                              &plugin_name))
      45             :   {
      46           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
      47             :                                "sync",
      48             :                                "db");
      49           0 :     return NULL;
      50             :   }
      51           1 :   (void) GNUNET_asprintf (&lib_name,
      52             :                           "libsync_plugin_db_%s",
      53             :                           plugin_name);
      54           1 :   GNUNET_free (plugin_name);
      55           1 :   plugin = GNUNET_PLUGIN_load (lib_name,
      56             :                                (void *) cfg);
      57           1 :   if (NULL != plugin)
      58           0 :     plugin->library_name = lib_name;
      59             :   else
      60           1 :     GNUNET_free (lib_name);
      61           1 :   return plugin;
      62             : }
      63             : 
      64             : 
      65             : /**
      66             :  * Shutdown the plugin.
      67             :  *
      68             :  * @param plugin the plugin to unload
      69             :  */
      70             : void
      71           0 : SYNC_DB_plugin_unload (struct SYNC_DatabasePlugin *plugin)
      72             : {
      73             :   char *lib_name;
      74             : 
      75           0 :   if (NULL == plugin)
      76           0 :     return;
      77           0 :   lib_name = plugin->library_name;
      78           0 :   GNUNET_assert (NULL == GNUNET_PLUGIN_unload (lib_name,
      79             :                                                plugin));
      80           0 :   GNUNET_free (lib_name);
      81             : }
      82             : 
      83             : 
      84             : /**
      85             :  * Libtool search path before we started.
      86             :  */
      87             : static char *old_dlsearchpath;
      88             : 
      89             : 
      90             : /**
      91             :  * Setup libtool paths.
      92             :  */
      93             : void __attribute__ ((constructor))
      94           1 : plugin_init ()
      95             : {
      96             :   int err;
      97             :   const char *opath;
      98             :   char *path;
      99             :   char *cpath;
     100             : 
     101           1 :   err = lt_dlinit ();
     102           1 :   if (err > 0)
     103             :   {
     104           0 :     fprintf (stderr,
     105             :              _ ("Initialization of plugin mechanism failed: %s!\n"),
     106             :              lt_dlerror ());
     107           0 :     return;
     108             :   }
     109           1 :   opath = lt_dlgetsearchpath ();
     110           1 :   if (NULL != opath)
     111           0 :     old_dlsearchpath = GNUNET_strdup (opath);
     112           1 :   path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR);
     113           1 :   if (NULL != path)
     114             :   {
     115           1 :     if (NULL != opath)
     116             :     {
     117           0 :       GNUNET_asprintf (&cpath, "%s:%s", opath, path);
     118           0 :       lt_dlsetsearchpath (cpath);
     119           0 :       GNUNET_free (path);
     120           0 :       GNUNET_free (cpath);
     121             :     }
     122             :     else
     123             :     {
     124           1 :       lt_dlsetsearchpath (path);
     125           1 :       GNUNET_free (path);
     126             :     }
     127             :   }
     128             : }
     129             : 
     130             : 
     131             : /**
     132             :  * Shutdown libtool.
     133             :  */
     134             : void __attribute__ ((destructor))
     135           1 : plugin_fini ()
     136             : {
     137           1 :   lt_dlsetsearchpath (old_dlsearchpath);
     138           1 :   if (NULL != old_dlsearchpath)
     139             :   {
     140           0 :     GNUNET_free (old_dlsearchpath);
     141           0 :     old_dlsearchpath = NULL;
     142             :   }
     143           1 :   lt_dlexit ();
     144           1 : }
     145             : 
     146             : 
     147             : /* end of sync_db_plugin.c */

Generated by: LCOV version 1.14