src/irc_log.c
changeset 100 cfb7776bd6f0
parent 88 233916a00429
child 109 bfe9b9a8fe5b
--- a/src/irc_log.c	Tue Mar 31 23:35:24 2009 +0300
+++ b/src/irc_log.c	Tue Mar 31 23:36:05 2009 +0300
@@ -440,31 +440,14 @@
  * Fails if the value is invalid, we don't have a database connected, the channel doesn't exist, adding our command
  * handlers/callbacks fails, or sending the initial INSERT-OPEN query fails.
  */
-static err_t irc_log_conf_channel (void *_ctx, char *value, struct error_info *err)
+static err_t irc_log_conf_channel (void *_ctx, struct irc_chan *chan, struct error_info *err)
 {
     struct irc_log_ctx *ctx = _ctx;
-    const char *network, *channel;
-    struct irc_chan *chan;
     
-    // parse required args
-    if ((network = strsep(&value, ":")) == NULL)
-        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "invalid <network> for irc_log.channel");
-        
-    if ((channel = strsep(&value, ":")) == NULL)
-        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "invalid <channel> for irc_log.channel");
-
-    // extraneous stuff?
-    if (value)
-        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "trailing data for irc_log.channel");
-
     // have a db configured?
     if (!ctx->db)
         RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "irc_log.channel used without any irc_log.db_info");
 
-    // get the channel?
-    if ((chan = irc_client_get_chan(ctx->nexus->client, network, channel)) == NULL)
-        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "unknown channel name");
-
     // begin logging it
     if (irc_log_chan(ctx, chan, err))
         return ERROR_CODE(err);
@@ -477,25 +460,11 @@
  * Our configuration options
  */
 struct config_option irc_log_config_options[] = {
-    {   "db_info",  CONFIG_STRING,  &irc_log_conf_db_info,  "[<key>=<value> [...]]",    "set database connection info, see libpq docs"  },
-    {   "channel",  CONFIG_STRING,  &irc_log_conf_channel,  "<network>:<channel>",      "log the given channel"                         },
-    {   NULL,       0,              NULL,                   NULL,                       NULL                                            }
-};
+    CONFIG_OPT_STRING(      "db_info",  &irc_log_conf_db_info,  "[<key>=<value> [...]]",    "set database connection info, see libpq docs"  ),
+    CONFIG_OPT_IRC_CHAN(    "channel",  &irc_log_conf_channel,  "<channel>",                "log the given channel"                         ),
 
-/**
- * Set a config option
- */
-static err_t irc_log_conf (void *_ctx, const char *name, char *value, struct error_info *err)
-{
-    struct irc_log_ctx *ctx = _ctx;
-
-    // wrong state
-    if (ctx->unloading)
-        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "module is being unloaded");
-    
-    // apply it
-    return config_apply(irc_log_config_options, ctx, name, value, err);
-}
+    CONFIG_OPT_END
+};
 
 /**
  * Deinitialize, logging CLOSE events for all channels, and removing any hooks we've added
@@ -520,9 +489,8 @@
 /**
  * The module function table
  */
-struct module_funcs irc_log_funcs = {
+struct module_desc irc_log_module = {
     .init               = &irc_log_init,
-    .conf               = &irc_log_conf,
     .config_options     = irc_log_config_options,
     .unload             = &irc_log_unload,
 };