]> jfr.im git - irc/thales.git/commitdiff
Added autogened query listings
authorDmitry Bogatov <redacted>
Wed, 9 Jan 2013 08:57:36 +0000 (12:57 +0400)
committerDmitry Bogatov <redacted>
Wed, 9 Jan 2013 08:57:36 +0000 (12:57 +0400)
configure.ac
src/Makefile.am
src/init_query.def [new file with mode: 0644]
src/init_query.tpl [new file with mode: 0644]
src/main.c
src/mysql_sentry.h [deleted file]
src/sentry.c [moved from src/mysql_sentry.c with 63% similarity]
src/sentry.h [new file with mode: 0644]

index 88da4cd2742c22d59f8ec5604cb1035e6de8d428..0a14ae651974d05676b3f98747803587e5feece4 100644 (file)
@@ -5,6 +5,8 @@ AC_CONFIG_AUX_DIR([build-aux])
 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
@@ -13,10 +15,10 @@ AC_CHECK_HEADER([libircclient/libircclient.h],[],
         [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.
 
index 87ee48003cc79c991c7f50d038d14d2f7010524a..d9a883b5d7da5a2ac942b6da3f624a8f79ce14f5 100644 (file)
@@ -1,10 +1,11 @@
 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}
diff --git a/src/init_query.def b/src/init_query.def
new file mode 100644 (file)
index 0000000..bf15d85
--- /dev/null
@@ -0,0 +1,59 @@
+# -*- 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.";
+};
diff --git a/src/init_query.tpl b/src/init_query.tpl
new file mode 100644 (file)
index 0000000..bae598a
--- /dev/null
@@ -0,0 +1,36 @@
+[+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 +]
index e5c685e0fca2034e46514a5ec370e30047777082..12ed9da678caf9195f14620e22f29b1133e5c5cd 100644 (file)
@@ -40,7 +40,7 @@ main (int argc, char **argv)
 
   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"); */
diff --git a/src/mysql_sentry.h b/src/mysql_sentry.h
deleted file mode 100644 (file)
index 8a77b71..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#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
similarity index 63%
rename from src/mysql_sentry.c
rename to src/sentry.c
index 41cc655f66f65c9072fb6c4a189354dbe1d47913..c5d4b796951dd5026b0f973e58c05125a69c7e97 100644 (file)
@@ -1,13 +1,13 @@
-#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
@@ -20,7 +20,7 @@ initialize_tables(MYSQL *db_handle)
 }
 
 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);
@@ -38,9 +38,10 @@ sentry_initialize (const struct mysql_options *opts)
     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:
@@ -48,3 +49,17 @@ sentry_initialize (const struct mysql_options *opts)
  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
+
+}
diff --git a/src/sentry.h b/src/sentry.h
new file mode 100644 (file)
index 0000000..6a79ac8
--- /dev/null
@@ -0,0 +1,12 @@
+#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