#include "irc.h"
-#include <stdlib.h>
#include <libircclient/libircclient.h>
+#include <libircclient/libirc_rfcnumeric.h>
+#include <stdlib.h>
#include <string.h>
#include "defaults.h"
#include "error.h"
#include "utility.h"
+#include "mysql_sentry.h"
#define EVENT_CALLBACK(function_name) void \
function_name (irc_session_t * session, const char *event, \
const struct irc_options *opts;
};
-static bool
-parse_message (const char *msg, char **name, char **payload)
+EVENT_CALLBACK(event_nick)
{
- const char *const shebang = "#!";
- const char *payload_begin;
-
- *name = *payload = NULL;
- if (strcmp (msg, shebang))
- return false; /* Is not command */
-
- /* Looks like command, but no terminating colon */
- if (!(payload_begin = strchr (msg, ':')))
- return false;
- *name = xrangedup (msg + strlen (shebang), payload_begin);
- *payload = xstrdup (payload_begin + 1);
- return true;
}
+
static
EVENT_CALLBACK (event_join)
{
- printf ("%s joined %s\n", origin, *params);
+ const char *nickname = origin;
+ const char *channel = *params;
+
+ printf ("%s joined %s\n", nickname, channel);
+ fflush(stdout);
+ irc_cmd_names(session, channel);
}
static
}
+static inline void
+event_numeric_namreply(struct context *context, const char *channel,
+ const char *nicknames)
+{
+ char *nicknames_buf = strdup(nicknames);
+
+ for (const char *nickname = strtok(nicknames_buf, " ");
+ nickname;
+ nickname = strtok(NULL, " "))
+ sentry_channel_presence_add(context->sentry, channel, nickname);
+
+ free(nicknames_buf);
+}
+
static void
event_numeric (irc_session_t * session, unsigned int
event, const char *origin, const char **params,
unsigned int count)
{
- printf ("Event =%d", event);
-}
+ struct context *context = irc_get_ctx(session);
+ switch (event) {
+ case LIBIRC_RFC_RPL_NAMREPLY:
+ assert(count >= 4);
+ const char *channel = params[2];
+ const char *nicknames = params[3];
+ event_numeric_namreply(context, channel, nicknames);
+ break;
+ }
+}
static
EVENT_CALLBACK (event_connect)
{
const struct context *ctx = irc_get_ctx (session);
- for (char **chan = ctx->opts->channels; *chan; ++chan)
+ printf("Connected!");
+ for (char **chan = ctx->opts->channels; *chan; ++chan) {
+ printf("sending connect request for %s\n", *chan);
irc_cmd_join (session, *chan, NULL);
+ }
+ fflush(stdout);
}
/* Question to libircclient. Why not const? */
.event_channel = event_channel,
.event_join = event_join,
.event_connect = event_connect,
- .event_numeric = event_numeric
+ .event_numeric = event_numeric,
+ .event_nick = event_nick
};
bool
opts->nick ? opts->nick : default_nick, NULL,
NULL);
if (error)
- fatal ("%s", irc_strerror (irc_errno (session)));
+ fatal ("error = %d, %s", error, irc_strerror (irc_errno (session)));
error = irc_run (session);
if (error)
fatal ("error = %d, %s", error, irc_strerror (irc_errno (session)));
#include "cmd.h"
#include "error.h"
#include "irc.h"
+#include "mysql_sentry.h"
int
main (int argc, char **argv)
{
- struct irc_options cmd_opts = { 0 };
+ struct irc_options irc_opts = { 0 };
struct mysql_options mysql_opts = { 0 };
struct config_options config_opts = { 0 };
- FILE *config_file;
- parse_cmd_options (&cmd_opts, &config_opts, argc, argv);
- config_file = config_opts.conf_filename ? fopen (config_opts.conf_filename, "r")
+
+ parse_cmd_options (&irc_opts, &config_opts, argc, argv);
+ FILE *config_file = config_opts.conf_filename ? fopen (config_opts.conf_filename, "r")
: default_config_file ();
if (!config_file)
fatal ("failed to open config file");
parse_mysql_options(&mysql_opts, config_file);
+
+SENTRY *sentry = sentry_initialize(&mysql_opts);
+#warning "mysql is not used"
+/* if (!sentry) */
+/* fatal("failed to connect to database"); */
+
+ start_listen_irc(&irc_opts, sentry);
return 0;
}