AM_INIT_AUTOMAKE
# Checks for programs.
AC_PROG_CC_C99
+AC_CHECK_PROGS([AUTOGEN], [autogen],
+ [AC_MSG_ERROR([GNU Autogen required, but not found])])
gl_EARLY
gl_INIT
AC_GNU_SOURCE
[AC_MSG_ERROR([libircclient header not found])])
AC_CHECK_LIB([ircclient],[irc_create_session],[],
[AC_MSG_ERROR([libircclient library not found])])
-AC_CHECK_HEADER([mysql/mysql.h],[],
- [AC_MSG_ERROR([Mysql header not found])])
-AC_CHECK_LIB([mysqlclient],[mysql_real_connect],[],
- [AC_MSG_ERROR([Mysql library not found])])
+AC_CHECK_HEADER([dbi/dbi.h],[],
+ [AC_MSG_ERROR([Libdbi headers not found])])
+AC_CHECK_LIB([dbi],[dbi_conn_new],[],
+ [AC_MSG_ERROR([Libdbi library not found])])
# Checks for typedefs, structures, and compiler characteristics.
AM_CFLAGS = -I$(top_srcdir)/lib
bin_PROGRAMS = thales
-thales_SOURCES = main.c cmd.h cmd.c worker.h \
+thales_SOURCES = main.c cmd.h cmd.c \
error.h irc.h irc.c defaults.c defaults.h \
- sentry.h mysql_sentry.h mysql_sentry.c
-
+ sentry.h sentry.c init_query.h init_query.c \
+ function_query.h function_query.c
thales_LDADD = $(top_builddir)/lib/libthales.a
+
check-syntax:
$(COMPILE) -o /dev/null -S ${CHK_SOURCES}
--- /dev/null
+# -*- conf-unix-*-
+autogen definitions init_query;
+query = {
+ value = "CREATE TABLE IF NOT EXISTS channel ("
+ "chanid int unsigned NOT NULL auto_increment,"
+ "channel varchar(33) binary NOT NULL default '',"
+ "topic text,"
+ "topicauthor varchar(31) default NULL,"
+ "topictime datetime default NULL,"
+ "PRIMARY KEY (chanid),"
+ "UNIQUE KEY channel (channel))";
+
+ error_msg = "Failed to create channel table.";
+};
+
+query = {
+ value = "CREATE TABLE IF NOT EXISTS user ("
+ "nickid int unsigned NOT NULL auto_increment,"
+ "nick varchar(31) NOT NULL default '',"
+ "realname varchar(51) NOT NULL default '',"
+ "hostname varchar(64) NOT NULL default '',"
+ "hiddenhostname varchar(64) NOT NULL default '',"
+ "username varchar(11) NOT NULL default '',"
+ "swhois varchar(32) NOT NULL default '',"
+ "connecttime datetime NOT NULL default '0000-00-00 00:00:00',"
+ "servid int unsigned NOT NULL default '0',"
+ "away enum('Y','N') NOT NULL default 'N',"
+ "awaymsg text,"
+ "online enum('Y','N') NOT NULL DEFAULT 'Y',"
+ "lastquit datetime default NULL,"
+ "PRIMARY KEY (nickid),"
+ "UNIQUE KEY nick (nick),"
+ "KEY servid (servid))";
+
+ error_msg = "Failed to create user table.";
+};
+
+query = {
+ value = "CREATE TABLE IF NOT EXISTS server ("
+ "servid int unsigned NOT NULL auto_increment,"
+ "server varchar(64) NOT NULL default '',"
+ "connecttime datetime default NULL,"
+ "PRIMARY KEY (servid),"
+ "UNIQUE KEY server (server))";
+
+ error_msg = "Failed to create server table.";
+};
+
+query = {
+ value = "CREATE TABLE IF NOT EXISTS presence ("
+ "nickid int unsigned NOT NULL default '0',"
+ "chanid int unsigned NOT NULL default '0',"
+ "servid int unsigned NOT NULL default '0',"
+ "PRIMARY KEY (nickid,chanid,servid),"
+ "KEY nickid (nickid),"
+ "KEY chanid (chanid))";
+
+ error_msg = "Failed to create presence table.";
+};
--- /dev/null
+[+autogen5 template h c +][+DEFINE
+GPL +]/*
+[+ (gpl "GNU Thales" " * " ) +]
+ */
+[+ENDDEF +][+DEFINE
+DO_NOT_EDIT +]/*
+[+(dne " * ") +]
+*/
+[+ENDDEF +][+
+CASE (suffix) +][+
+== h +][+ DO_NOT_EDIT +]
+[+GPL+]
+[+ (make-header-guard "") +]
+
+#define INIT_QUERIES_COUNT [+ (count "query") +]
+extern char const *init_queries[ INIT_QUERIES_COUNT ];
+extern char const *init_queries_error_messages[ INIT_QUERIES_COUNT];
+#endif /* [+ (. header-guard) +] */ [+
+== c +][+ DO_NOT_EDIT +]
+[+ GPL +]
+
+#include "[+ (. header-file) +]"
+
+char const *init_queries[] = { [+
+FOR query "," +]
+ "[+ value +]"[+
+ENDFOR query +]
+};
+
+char const *init_queries_error_messages[] = { [+
+FOR query "," +]
+ "[+ error_msg +]"[+
+ENDFOR query +]
+};
+
+[+ESAC +]
parse_mysql_options(&mysql_opts, config_file);
-SENTRY *sentry = sentry_initialize(&mysql_opts);
+SENTRY *sentry = sentry_initialize(&mysql_opts, irc_opts.server);
#warning "mysql is not used"
/* if (!sentry) */
/* fatal("failed to connect to database"); */
+++ /dev/null
-#ifndef MYSQL_SENTRY_H
-#define MYSQL_SENTRY_H
-#include <stdbool.h>
-struct mysql_options;
-struct sentry;
-typedef struct sentry SENTRY;
-
-SENTRY *sentry_initialize(const struct mysql_options *opts);
-bool sentry_channel_presence_clear(SENTRY *sentry, const char *channel);
-bool sentry_channel_presence_add(SENTRY *sentry, const char *channel,
- const char *nickname);
-
-bool sentry_update_presence(SENTRY *sentry,
- const char *nickname, const char *channel, bool online);
-
-
-#endif
-#include "mysql_sentry.h"
-#include <mysql/mysql.h>
+#include "sentry.h"
#include <xalloc.h>
#include <stdbool.h>
+#include <dbi/dbi.h>
#include "cmd.h"
#include "init_queries.sql.h"
struct sentry
{
- MYSQL db_handle;
+char *unused;
};
static inline bool
}
SENTRY *
-sentry_initialize (const struct mysql_options *opts)
+sentry_initialize (const struct mysql_options *opts, const char *server)
{
MYSQL db_handle;
mysql_init (&db_handle);
goto tables;
}
- struct sentry *new = xmalloc (sizeof *new);
+ struct sentry *new = xcalloc (1, sizeof *new);
new->db_handle = db_handle;
+ new->server = xstrdup(server);
return new;
tables:
connect:
return NULL;
}
+
+void
+sentry_channel_presence_clear(SENTRY *sentry, const char *channel)
+{
+ static const char *query =
+}
+
+void
+sentry_channel_presence_add(SENTRY *sentry, const char *channel,
+ const char *nickname)
+{
+ const char *query = "INSERT INTO presence VALUES (nickid, chanid, servid) where
+
+}
--- /dev/null
+#ifndef SENTRY_H
+#define SENTRY_H
+#include <stdbool.h>
+struct db_options;
+struct sentry;
+typedef struct sentry SENTRY;
+
+SENTRY *sentry_initialize(const struct db_options *opts, const char *server);
+void sentry_channel_presence_clear(SENTRY *sentry, const char *channel);
+void sentry_channel_presence_add(SENTRY *sentry, const char *channel,
+ const char *nickname);
+#endif