]> jfr.im git - irc/thales.git/blob - src/sentry.c
c5d4b796951dd5026b0f973e58c05125a69c7e97
[irc/thales.git] / src / sentry.c
1 #include "sentry.h"
2 #include <xalloc.h>
3 #include <stdbool.h>
4 #include <dbi/dbi.h>
5 #include "cmd.h"
6 #include "init_queries.sql.h"
7
8 struct sentry
9 {
10 char *unused;
11 };
12
13 static inline bool
14 initialize_tables(MYSQL *db_handle)
15 {
16 for (const char *query = *init_queries(); *query; ++query)
17 if (!mysql_query(db_handle, query))
18 return false;
19 return true;
20 }
21
22 SENTRY *
23 sentry_initialize (const struct mysql_options *opts, const char *server)
24 {
25 MYSQL db_handle;
26 mysql_init (&db_handle);
27 if (!mysql_real_connect (&db_handle, opts->host, opts->username,
28 opts->password, opts->database, opts->port,
29 NULL, 0))
30 {
31 fprintf(stderr, "Failed to connect to database: Error: %s\n",
32 mysql_error(&db_handle));
33 goto connect;
34 }
35 if (!initialize_tables(&db_handle)) {
36 fprintf(stderr, "Failed to connect to database: Error: %s\n",
37 mysql_error(&db_handle));
38 goto tables;
39 }
40
41 struct sentry *new = xcalloc (1, sizeof *new);
42
43 new->db_handle = db_handle;
44 new->server = xstrdup(server);
45 return new;
46
47 tables:
48 mysql_close(&db_handle);
49 connect:
50 return NULL;
51 }
52
53 void
54 sentry_channel_presence_clear(SENTRY *sentry, const char *channel)
55 {
56 static const char *query =
57 }
58
59 void
60 sentry_channel_presence_add(SENTRY *sentry, const char *channel,
61 const char *nickname)
62 {
63 const char *query = "INSERT INTO presence VALUES (nickid, chanid, servid) where
64
65 }