Initial import
This commit is contained in:
6
libwmud-state-sqlite3/Makefile.am
Normal file
6
libwmud-state-sqlite3/Makefile.am
Normal file
@@ -0,0 +1,6 @@
|
||||
LIBWMUD_STATE_SQLITE3_VERSION=1:0:0
|
||||
lib_LTLIBRARIES = libwmud-state-sqlite3-1.0.la
|
||||
libwmud_state_sqlite3_1_0_la_SOURCES = wmud-state-sqlite3.c
|
||||
libwmud_state_sqlite3_1_0_la_CFLAGS = $(CFLAGS) $(GLIB_CFLAGS) $(GOBJECT_CFLAGS) $(GNET_CFLAGS) -Wall -I../src -I../libwmud-session
|
||||
libwmud_state_sqlite3_1_0_la_LIBADD = $(LIBS) $(GLIB_LIBS) $(GOBJECT_LIBS) $(GNET_LIBS)
|
||||
libwmud_state_sqlite3_1_0_la_LDFLAGS = -version-info $(LIBWMUD_STATE_SQLITE3_VERSION)
|
91
libwmud-state-sqlite3/wmud-state-sqlite3.c
Normal file
91
libwmud-state-sqlite3/wmud-state-sqlite3.c
Normal file
@@ -0,0 +1,91 @@
|
||||
#include <glib.h>
|
||||
#include <sqlite3.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "module.h"
|
||||
|
||||
static gchar *state_file = NULL;
|
||||
static sqlite3 *statesave_connection = NULL;
|
||||
|
||||
gboolean
|
||||
wmud_statesave_sqlite3_is_statesave(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gint
|
||||
_wmud_statesave_sqlite3_find_config_group(gconstpointer list_data, gconstpointer lookup_data)
|
||||
{
|
||||
wMUDConfigurationGroup *group = (wMUDConfigurationGroup *)list_data;
|
||||
gchar *name_to_find = (gchar *)lookup_data;
|
||||
|
||||
Context return g_utf8_collate(group->name, name_to_find);
|
||||
}
|
||||
|
||||
static void
|
||||
_wmud_statesave_sqlite3_parse_config(gpointer data, gpointer userdata)
|
||||
{
|
||||
wMUDConfigurationValue *parameter = (wMUDConfigurationValue *)data;
|
||||
|
||||
if (g_utf8_collate("state file", parameter->key) == 0)
|
||||
{
|
||||
state_file = g_strdup(parameter->value);
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
wmud_statesave_sqlite3_load(wMUDConfiguration *config)
|
||||
{
|
||||
GSList *statesave_params;
|
||||
wMUDConfigurationGroup *config_group;
|
||||
|
||||
wmud_log_debug("Initializing SQLite3 state saving module...");
|
||||
|
||||
if (!sqlite3_threadsafe())
|
||||
{
|
||||
wmud_log_error("SQLite3 library is not compiled in a thread-safe manner.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Context statesave_params = g_slist_find_custom(config->statesave_parameters, "sqlite3", _wmud_statesave_sqlite3_find_config_group);
|
||||
|
||||
if (statesave_params == NULL)
|
||||
{
|
||||
wmud_log_error("Cannot find group [statesave sqlite3] in configfile!");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
config_group = (wMUDConfigurationGroup *)(statesave_params->data);
|
||||
g_slist_foreach(config_group->datalist, _wmud_statesave_sqlite3_parse_config, NULL);
|
||||
|
||||
if (state_file == NULL)
|
||||
{
|
||||
wmud_log_error("Cannot find state file parameter in configuration file (should be under group [statesave sqlite3]");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wmud_log_debug("Will save state into SQLite3 file %s", state_file);
|
||||
|
||||
switch (sqlite3_open(state_file, &statesave_connection))
|
||||
{
|
||||
case SQLITE_OK:
|
||||
wmud_log_info("State file opened successfully");
|
||||
break;
|
||||
default:
|
||||
wmud_log_error("Unprocessed return value from sqlite3_open()!");
|
||||
return FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
wmud_statesave_sqlite3_unload(void)
|
||||
{
|
||||
sqlite3_close(statesave_connection);
|
||||
}
|
||||
|
0
libwmud-state-sqlite3/wmud-state-sqlite3.h
Normal file
0
libwmud-state-sqlite3/wmud-state-sqlite3.h
Normal file
Reference in New Issue
Block a user