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 6 : 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 6 : if (GNUNET_SYSERR == 37 6 : 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 6 : (void) GNUNET_asprintf (&lib_name, 48 : "libtaler_plugin_merchantdb_%s", 49 : plugin_name); 50 6 : GNUNET_free (plugin_name); 51 6 : plugin = GNUNET_PLUGIN_load (lib_name, 52 : (void *) cfg); 53 6 : if (NULL == plugin) 54 : { 55 0 : GNUNET_free (lib_name); 56 0 : return NULL; 57 : } 58 6 : plugin->library_name = lib_name; 59 6 : return plugin; 60 : } 61 : 62 : 63 : void 64 5 : TALER_MERCHANTDB_plugin_unload (struct TALER_MERCHANTDB_Plugin *plugin) 65 : { 66 : char *lib_name; 67 : 68 5 : if (NULL == plugin) 69 0 : return; 70 5 : lib_name = plugin->library_name; 71 5 : GNUNET_assert (NULL == GNUNET_PLUGIN_unload (lib_name, 72 : plugin)); 73 5 : 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 20 : plugin_init (void) 88 : { 89 : int err; 90 : const char *opath; 91 : char *path; 92 : char *cpath; 93 : 94 20 : err = lt_dlinit (); 95 20 : if (err > 0) 96 : { 97 0 : fprintf (stderr, 98 : _ ("Initialization of plugin mechanism failed: %s!\n"), 99 : lt_dlerror ()); 100 0 : return; 101 : } 102 20 : opath = lt_dlgetsearchpath (); 103 20 : if (NULL != opath) 104 0 : old_dlsearchpath = GNUNET_strdup (opath); 105 20 : path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR); 106 20 : if (NULL != path) 107 : { 108 20 : 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 20 : lt_dlsetsearchpath (path); 118 20 : GNUNET_free (path); 119 : } 120 : } 121 : } 122 : 123 : 124 : /** 125 : * Shutdown libtool. 126 : */ 127 : void __attribute__ ((destructor)) 128 20 : plugin_fini (void) 129 : { 130 20 : lt_dlsetsearchpath (old_dlsearchpath); 131 20 : if (NULL != old_dlsearchpath) 132 : { 133 0 : GNUNET_free (old_dlsearchpath); 134 0 : old_dlsearchpath = NULL; 135 : } 136 20 : lt_dlexit (); 137 20 : } 138 : 139 : 140 : /* end of merchantdb_plugin.c */