add --module support, and tweak irc_net docs
authorTero Marttila <terom@fixme.fi>
Mon, 16 Mar 2009 01:03:41 +0200
changeset 65 d7508879ad01
parent 64 81cc5b8c5abc
child 66 ef8c9d7daf62
add --module support, and tweak irc_net docs
src/irc_log.c
src/irc_net.h
src/module.c
src/module.h
src/nexus.c
--- a/src/irc_log.c	Mon Mar 16 00:55:45 2009 +0200
+++ b/src/irc_log.c	Mon Mar 16 01:03:41 2009 +0200
@@ -55,6 +55,8 @@
     // store
     ctx->nexus = nexus;
 
+    log_info("module initialized");
+
     // ok
     *ctx_ptr = ctx;
 
--- a/src/irc_net.h	Mon Mar 16 00:55:45 2009 +0200
+++ b/src/irc_net.h	Mon Mar 16 01:03:41 2009 +0200
@@ -59,7 +59,7 @@
  *
  * @param net the new irc_net struct is returned via this pointer
  * @param info network informated, used to connect and register
- * @param err used to return extended error information
+ * @param err return error info
  */
 err_t irc_net_create (struct irc_net **net, const struct irc_net_info *info, struct error_info *err);
 
@@ -73,6 +73,11 @@
  * Create a new irc_chan and add it to our channel list.
  *
  * If we are connected and registered, JOIN the channel right away, otherwise, join it once we register.
+ *
+ * @param net the irc_net the channel is on
+ * #param chan_ptr return the new irc_chan via this, if not NULL
+ * @param info the info required to identify and join the channel
+ * @param err return error info
  */
 err_t irc_net_add_chan (struct irc_net *net, struct irc_chan **chan_ptr, const struct irc_chan_info *info, struct error_info *err);
 
--- a/src/module.c	Mon Mar 16 00:55:45 2009 +0200
+++ b/src/module.c	Mon Mar 16 01:03:41 2009 +0200
@@ -82,7 +82,8 @@
     TAILQ_INSERT_TAIL(&modules->list, module, modules_list);
 
     // ok
-    *module_ptr = module;
+    if (module_ptr)
+        *module_ptr = module;
 
     return SUCCESS;
 
--- a/src/module.h	Mon Mar 16 00:55:45 2009 +0200
+++ b/src/module.h	Mon Mar 16 01:03:41 2009 +0200
@@ -123,6 +123,11 @@
 
 /**
  * Load a new module
+ *
+ * @param modules the module-loading context
+ * @param module_ptr return the new module via this, if not NULL
+ * @param info the info required to identify and load the module
+ * @param err return error info
  */
 err_t module_load (struct modules *modules, struct module **module_ptr, const struct module_info *info, struct error_info *err);
 
--- a/src/nexus.c	Mon Mar 16 00:55:45 2009 +0200
+++ b/src/nexus.c	Mon Mar 16 01:03:41 2009 +0200
@@ -55,7 +55,7 @@
 }
 
 /**
- * Parse and apply a --network option
+ * Parse and apply a --network option, adding the given network to our irc_client.
  */
 static err_t apply_network (struct nexus *nexus, char *opt, struct error_info *err)
 {
@@ -93,6 +93,8 @@
             RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "unrecognized flag for --network");
     }
 
+    log_info("add network '%s' at '%s:%s'", info.network, info.hostname, info.service);
+
     // create the net
     if (irc_client_add_net(nexus->client, NULL, &info, err))
         return ERROR_CODE(err);
@@ -102,7 +104,7 @@
 }
 
 /**
- * Parse and apply a --channel option
+ * Parse and apply a --channel option, adding the given channel to the given irc_net.
  */
 static err_t apply_channel (struct nexus *nexus, char *opt, struct error_info *err)
 {
@@ -126,6 +128,8 @@
     // look up the net
     if ((net = irc_client_get_net(nexus->client, network)) == NULL)
         RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "unknown network for --channel");
+    
+    log_info("add channel '%s' on network '%s'", info.channel, net->info.network);
 
     // add the channel
     if (irc_net_add_chan(net, NULL, &info, err))
@@ -136,6 +140,38 @@
 }
 
 /**
+ * Parse and apply a --module option, loading the given module.
+ */
+static err_t apply_module (struct nexus *nexus, char *opt, struct error_info *err)
+{
+    struct module_info info = {
+        .name       = NULL,
+        .path       = NULL,
+    };
+    struct module *module;
+
+    // parse the required fields
+    if ((info.name = strsep(&opt, ":")) == NULL)
+        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <name> field for --module");
+
+    if ((info.path = strsep(&opt, ":")) == NULL)
+        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <path> field for --module");
+
+    // trailing garbage?
+    if (opt)
+        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "trailing values for --channel");
+    
+    log_info("loading module '%s' from path '%s'", info.name, info.path);
+
+    // load it
+    if (module_load(nexus->modules, &module, &info, err))
+        return ERROR_CODE(err);
+
+    // ok
+    return SUCCESS;
+}
+
+/**
  * Parse arguments and apply them to the given nexus
  */
 static err_t parse_args (struct nexus *nexus, int argc, char **argv, struct error_info *err)
@@ -164,6 +200,11 @@
                 break;
             
             case OPT_MODULE:
+                if (apply_module(nexus, optarg, err))
+                    return ERROR_CODE(err);
+
+                break;
+
             case OPT_CONFIG:
                 RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "option unimplemented");