indentation
[oweals/gnunet.git] / src / dht / dhtlog.c
1 /*
2      This file is part of GNUnet.
3      (C) 2006 - 2009 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 2, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file src/dht/dhtlog.c
23  * @brief Plugin loaded to load logging
24  *        to record DHT operations
25  * @author Nathan Evans
26  *
27  * Database: Loaded by plugin MySQL
28  */
29
30 #include "platform.h"
31 #include "gnunet_util_lib.h"
32 #include "dhtlog.h"
33
34 static char *libname;
35
36 /*
37  * Provides the dhtlog api
38  *
39  * @param c the configuration to use to connect to a server
40  *
41  * @return the handle to the server, or NULL on error
42  */
43 struct GNUNET_DHTLOG_Handle *
44 GNUNET_DHTLOG_connect (const struct GNUNET_CONFIGURATION_Handle *c)
45 {
46   struct GNUNET_DHTLOG_Plugin *plugin;
47   struct GNUNET_DHTLOG_Handle *api;
48   char *plugin_name;
49
50   plugin = GNUNET_malloc (sizeof (struct GNUNET_DHTLOG_Plugin));
51   plugin->cfg = c;
52   if (GNUNET_OK ==
53       GNUNET_CONFIGURATION_get_value_string (c,
54                                              "DHTLOG", "PLUGIN", &plugin_name))
55   {
56     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
57                 _("Loading `%s' dhtlog plugin\n"), plugin_name);
58     GNUNET_asprintf (&libname, "libgnunet_plugin_dhtlog_%s", plugin_name);
59     GNUNET_PLUGIN_load (libname, plugin);
60   }
61
62   if (plugin->dhtlog_api == NULL)
63   {
64     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
65                 _("Failed to load dhtlog plugin for `%s'\n"), plugin_name);
66     GNUNET_free (plugin_name);
67     GNUNET_free (plugin);
68     return NULL;
69   }
70
71   api = plugin->dhtlog_api;
72   GNUNET_free (plugin_name);
73   GNUNET_free (plugin);
74   return api;
75 }
76
77 /**
78  * Shutdown the module.
79  */
80 void
81 GNUNET_DHTLOG_disconnect (struct GNUNET_DHTLOG_Handle *api)
82 {
83 #if DEBUG_DHTLOG
84   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL DHT Logger: database shutdown\n");
85 #endif
86   if (api != NULL)
87   {
88     GNUNET_PLUGIN_unload (libname, api);
89   }
90   GNUNET_free_non_null (libname);
91 }
92
93 /* end of dhtlog.c */