]> jfr.im git - irc/thales.git/commitdiff
Added query template. Need to get sql magic
authorDmitry Bogatov <redacted>
Wed, 23 Jan 2013 13:05:14 +0000 (17:05 +0400)
committerDmitry Bogatov <redacted>
Wed, 23 Jan 2013 13:05:14 +0000 (17:05 +0400)
src/init_queries.sql.h [deleted file]
src/irc.c
src/irc.h
src/main.c
src/query.def [new file with mode: 0644]
src/query.tpl [new file with mode: 0644]
src/sentry.c

diff --git a/src/init_queries.sql.h b/src/init_queries.sql.h
deleted file mode 100644 (file)
index 9120fc5..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#ifndef INIT_QUERIES_H
-#define INIT_QUERIES_H
-static const char *channel_tbl =
-  "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))";
-
-static const char *user_tbl =
-  "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))";
-
-static const char * server_tbl =
-  "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))";
-
-static const char *presence_tbl =
-  "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))";
-
-/* Stupid restriction of C */
-static inline const char **
-init_queries ()
-{
-  enum { query_count = 5 };
-  static const char *queries[query_count] = { 0 };
-  queries[0] = user_tbl;
-  queries[1] = presence_tbl;
-  queries[2] = server_tbl;
-  queries[3] = channel_tbl;
-  queries[4] = NULL;
-  return queries;
-}
-#endif
index 6dd03cba9a72b584cad6f869215441d4e053cfa7..6f392acc1ccf3076687853094c54158677c93383 100644 (file)
--- a/src/irc.c
+++ b/src/irc.c
@@ -6,7 +6,7 @@
 #include "defaults.h"
 #include "error.h"
 #include "utility.h"
-#include "mysql_sentry.h"
+#include "sentry.h"
 
 #define EVENT_CALLBACK(function_name) void                              \
   function_name (irc_session_t * session, const char *event,            \
@@ -28,9 +28,11 @@ EVENT_CALLBACK (event_join)
 {
   const char *nickname =  origin;
   const char *channel = *params;
+  const struct context *ctx = irc_get_ctx(session);
 
   printf ("%s joined %s\n", nickname, channel);
   fflush(stdout);
+  sentry_channel_presence_clear(ctx, channel);
   irc_cmd_names(session, channel);
 }
 
@@ -49,7 +51,9 @@ event_numeric_namreply(struct context *context, const char *channel,
   for (const char *nickname = strtok(nicknames_buf, " ");
        nickname;
        nickname = strtok(NULL, " "))
-    sentry_channel_presence_add(context->sentry, channel, nickname);
+    {
+      sentry_channel_presence_add(context->sentry, channel, nickname);
+    }
 
   free(nicknames_buf);
 }
@@ -107,7 +111,7 @@ start_listen_irc (const struct irc_options *opts,
   irc_set_ctx (session, &context);
   int error = irc_connect (session,
                            opts->server ? opts->server : default_server,
-                           opts->port ? opts->port : default_port, NULL,       /* Password. Not now. */
+                           opts->port ? opts->port : default_port, NULL,       /* Password*/
                           opts->nick ? opts->nick : default_nick, NULL,
                           NULL);
   if (error)
index f249626ae3ae0f6c09637b9581a0c95917193d75..292f53219ef17c05e0c652206806e1ace034e209 100644 (file)
--- a/src/irc.h
+++ b/src/irc.h
@@ -2,7 +2,7 @@
 #define IRC_H
 #include <stdbool.h>
 #include "cmd.h"
-#include "mysql_sentry.h"
+#include "sentry.h"
 struct irc_user {
   char *nickname;
   char *realname;
index 12ed9da678caf9195f14620e22f29b1133e5c5cd..cc130f59364acd41f04fffffbff0def93c8d783c 100644 (file)
@@ -21,7 +21,7 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "cmd.h"
 #include "error.h"
 #include "irc.h"
-#include "mysql_sentry.h"
+#include "sentry.h"
 
 int
 main (int argc, char **argv)
diff --git a/src/query.def b/src/query.def
new file mode 100644 (file)
index 0000000..8826bef
--- /dev/null
@@ -0,0 +1,13 @@
+# -*- conf-unix-*-
+autogen definitions query;
+query = {
+  def = "CHANNEL_PRESENCE_CLEAR";
+  value = "clear?!";
+  error_msg = "Failed to clear?!";
+  comment = "Optional";
+};
+query = {
+  def = "CHANNEL_PRESENCE_ADD";
+  value = "add?!";
+  error_msg = "Failed to add?!";
+};
\ No newline at end of file
diff --git a/src/query.tpl b/src/query.tpl
new file mode 100644 (file)
index 0000000..fc8727e
--- /dev/null
@@ -0,0 +1,41 @@
+[+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 "") +]
+
+[+FOR query "" +]
+/* [+ comment +] */
+#define QUERY_[+def+] [+ (for-index) +]
+[+ENDFOR query +]
+
+#define QUERIES_COUNT [+ (count "query") +]
+extern char const *queries[ QUERIES_COUNT ];
+extern char const *queries_error_messages[ QUERIES_COUNT];
+#endif /* [+ (. header-guard) +] */ [+
+==  c  +][+ DO_NOT_EDIT +]
+[+ GPL +]
+
+#include "[+ (. header-file)  +]"
+
+char const *queries[] = { [+
+FOR query "," +]
+  "[+ value +]"[+
+ENDFOR query +]
+};
+
+char const *queries_error_messages[] = { [+
+FOR query "," +]
+  "[+ error_msg +]"[+
+ENDFOR query +]
+};
+
+[+ESAC +]
index c5d4b796951dd5026b0f973e58c05125a69c7e97..79c738ff3e2dd1ef6c38b802b86e4d92be8d36ee 100644 (file)
@@ -3,17 +3,17 @@
 #include <stdbool.h>
 #include <dbi/dbi.h>
 #include "cmd.h"
-#include "init_queries.sql.h"
+#include "init_query.h"
 
 struct sentry
 {
-char *unused;
+  char *unused;
 };
 
 static inline bool
 initialize_tables(MYSQL *db_handle)
 {
-  for (const char *query = *init_queries(); *query; ++query)
+  for (const char *query = *init_queries; *query; ++query)
     if (!mysql_query(db_handle, query))
       return false;
   return true;
@@ -38,7 +38,7 @@ sentry_initialize (const struct mysql_options *opts, const char *server)
     goto tables;
   }
 
-  struct sentry *new = xcalloc (1, sizeof *new);
+  struct sentry *new = xmalloc (sizeof *new);
 
   new->db_handle = db_handle;
   new->server = xstrdup(server);
@@ -60,6 +60,6 @@ void
 sentry_channel_presence_add(SENTRY *sentry, const char *channel,
                             const char *nickname)
 {
-  const char *query = "INSERT INTO presence VALUES (nickid, chanid, servid) where
+  const char *query = "INSERT INTO presence VALUES (nickid, chanid, servid) where"
 
 }