challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

challenger_db_plugin.c (2711B)


      1 /*
      2   This file is part of Challenger
      3   Copyright (C) 2019 Taler Systems SA
      4 
      5   Challenger 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   Challenger 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   Challenger; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file challengerdb/challenger_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 "challenger_util.h"
     24 #include "challenger_database_lib.h"
     25 #include <ltdl.h>
     26 
     27 
     28 struct CHALLENGER_DatabasePlugin *
     29 CHALLENGER_DB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg,
     30                            bool skip_preflight)
     31 {
     32   char *plugin_name;
     33   char *lib_name;
     34   struct CHALLENGER_DatabasePlugin *plugin;
     35 
     36   if (GNUNET_SYSERR ==
     37       GNUNET_CONFIGURATION_get_value_string (cfg,
     38                                              "challenger",
     39                                              "db",
     40                                              &plugin_name))
     41   {
     42     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     43                                "challenger",
     44                                "db");
     45     return NULL;
     46   }
     47   (void) GNUNET_asprintf (&lib_name,
     48                           "libchallenger_plugin_db_%s",
     49                           plugin_name);
     50   GNUNET_free (plugin_name);
     51   plugin = GNUNET_PLUGIN_load (CHALLENGER_project_data (),
     52                                lib_name,
     53                                (void *) cfg);
     54   if (NULL == plugin)
     55   {
     56     GNUNET_free (lib_name);
     57     return NULL;
     58   }
     59   plugin->library_name = lib_name;
     60   if ( (! skip_preflight) &&
     61        (GNUNET_OK !=
     62         plugin->preflight (plugin->cls)) )
     63   {
     64     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     65                 "Database not ready. Try running challenger-dbinit!\n");
     66     CHALLENGER_DB_plugin_unload (plugin);
     67     return NULL;
     68   }
     69   return plugin;
     70 }
     71 
     72 
     73 void
     74 CHALLENGER_DB_plugin_unload (struct CHALLENGER_DatabasePlugin *plugin)
     75 {
     76   char *lib_name;
     77 
     78   if (NULL == plugin)
     79     return;
     80   lib_name = plugin->library_name;
     81   GNUNET_assert (NULL == GNUNET_PLUGIN_unload (lib_name,
     82                                                plugin));
     83   GNUNET_free (lib_name);
     84 }
     85 
     86 
     87 /* end of challenger_db_plugin.c */