exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

auditordb_plugin.c (2771B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2015, 2016 Taler Systems SA
      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  * @file auditordb/auditordb_plugin.c
     18  * @brief Logic to load database plugin
     19  * @author Christian Grothoff
     20  * @author Sree Harsha Totakura <sreeharsha@totakura.in>
     21  */
     22 #include "taler/platform.h"
     23 #include "taler/taler_auditordb_plugin.h"
     24 #include <ltdl.h>
     25 
     26 
     27 struct TALER_AUDITORDB_Plugin *
     28 TALER_AUDITORDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg,
     29                              bool skip_preflight)
     30 {
     31   char *plugin_name;
     32   char *lib_name;
     33   struct TALER_AUDITORDB_Plugin *plugin;
     34 
     35   if (GNUNET_SYSERR ==
     36       GNUNET_CONFIGURATION_get_value_string (cfg,
     37                                              "auditor",
     38                                              "db",
     39                                              &plugin_name))
     40   {
     41     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     42                                "auditor",
     43                                "db");
     44     return NULL;
     45   }
     46   (void) GNUNET_asprintf (&lib_name,
     47                           "libtaler_plugin_auditordb_%s",
     48                           plugin_name);
     49   GNUNET_free (plugin_name);
     50   plugin = GNUNET_PLUGIN_load (TALER_AUDITOR_project_data (),
     51                                lib_name,
     52                                (void *) cfg);
     53   if (NULL == plugin)
     54   {
     55     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     56                 "Failed to load `%s'\n",
     57                 lib_name);
     58     GNUNET_free (lib_name);
     59     return NULL;
     60   }
     61   plugin->library_name = lib_name;
     62   if ( (! skip_preflight) &&
     63        (GNUNET_OK !=
     64         plugin->preflight (plugin->cls)) )
     65   {
     66     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     67                 "Database not ready. Try running taler-auditor-dbinit!\n");
     68     TALER_AUDITORDB_plugin_unload (plugin);
     69     return NULL;
     70   }
     71   return plugin;
     72 }
     73 
     74 
     75 void
     76 TALER_AUDITORDB_plugin_unload (struct TALER_AUDITORDB_Plugin *plugin)
     77 {
     78   char *lib_name;
     79 
     80   if (NULL == plugin)
     81     return;
     82   lib_name = plugin->library_name;
     83   GNUNET_assert (NULL == GNUNET_PLUGIN_unload (lib_name,
     84                                                plugin));
     85   GNUNET_free (lib_name);
     86 }
     87 
     88 
     89 /* end of auditordb_plugin.c */