src/modules/logwatch.h
changeset 132 f2ece471fb07
parent 130 ffefb6d85ea6
child 133 e2d0c0c23b39
--- a/src/modules/logwatch.h	Sat Apr 11 06:03:49 2009 +0300
+++ b/src/modules/logwatch.h	Sun Apr 12 17:18:06 2009 +0300
@@ -20,6 +20,9 @@
     /** The logwatch context we are registered to */
     struct logwatch *ctx;
 
+    /** Our name */
+    char *name;
+
     /** The input FIFO */
     struct line_proto *lp;
 
@@ -33,6 +36,23 @@
 #define LOGWATCH_SOURCE_LINE_MAX 1024
 
 /**
+ * Logwatch's per-channel state
+ */
+struct logwatch_chan {
+    /** The logwatch context we are registered to */
+    struct logwatch *ctx;
+
+    /** The actual irc_chan */
+    struct irc_chan *irc_chan;
+
+    /** Number of references */
+    size_t refcount;
+
+    /** Our entry in logwatch::channels */
+    TAILQ_ENTRY(logwatch_chan) logwatch_channels;
+};
+
+/**
  * A filter specifies what lines to match, and how to then format the output.
  */
 struct logwatch_filter {
@@ -58,7 +78,7 @@
     /**
      * The channel to send output to 
      */
-    struct irc_chan *chan;
+    struct logwatch_chan *chan;
 
     /** Our entry in logwatch::filters */
     TAILQ_ENTRY(logwatch_filter) logwatch_filters;
@@ -75,19 +95,6 @@
 #define LOGWATCH_FILTER_OUT_MAX 450
 
 /**
- * A channel for outputting logwatch output
- *
- * XXX; do we need this?
- */
-struct logwatch_chan {
-    /** The channel... */
-    struct irc_chan *chan;
-
-    /** Our entry in logwatch::channels */
-    TAILQ_ENTRY(logwatch_chan) logwatch_channels;
-};
-
-/**
  * The logwatch module state
  */
 struct logwatch {
@@ -100,7 +107,7 @@
     /** List of filters */
     TAILQ_HEAD(logwatch_filter_list, logwatch_filter) filters;
 
-    /** List of output channels */
+    /** List of chanenls */
     TAILQ_HEAD(logwatch_chan_list, logwatch_chan) channels;
 };
 
@@ -108,7 +115,7 @@
  * Add a new FIFO logwatch_source
  *
  * @param ctx the logwatch state
- * @param path the path to the fifo
+ * @param path the path to the fifo, also used as the name
  * @param err returned error info
  * @return the new logwatch_source, or NULL on error
  */
@@ -117,22 +124,35 @@
 /**
  * Destroy a source, removing it from the list of sources.
  *
- * XXX: remove all affected filters as well?
+ * XXX: remove all affected filters as well
  */
 void logwatch_source_destroy (struct logwatch_source *source);
 
 /**
- * Add a new output channel
+ * Lookup a logwatch_source by name
+ */
+const struct logwatch_source* logwatch_source_lookup (struct logwatch *ctx, const char *name);
+
+/**
+ * Find an existing logwatch_chan for the given channel, or create a new one. Returns a real reference that should be
+ * returned using logwatch_put_chan().
  *
- * XXX; do we need this?
+ * @returns NULL on ERR_CALLOC
  */
-struct logwatch_chan* logwatch_add_chan (struct logwatch *ctx, struct irc_chan *chan, struct error_info *err);
+struct logwatch_chan* logwatch_get_chan (struct logwatch *ctx, struct irc_chan *irc_chan);
+
+/**
+ * Returns a reference aquired using logwatch_get_chan().
+ */
+void logwatch_put_chan (struct logwatch_chan *chan);
 
 /**
  * Add a new filter.
+ *
+ * The given logwatch_chan should be a new reference.
  */
 struct logwatch_filter* logwatch_filter (struct logwatch *ctx, const char *name, const struct logwatch_source *source,
-        const char *pattern, const char *fmt, struct irc_chan *chan, struct error_info *err);
+        const char *pattern, const char *format, struct logwatch_chan *chan, struct error_info *err);
 
 /**
  * Destroy a logwatch_filter, unregistering it
@@ -145,7 +165,16 @@
 err_t logwatch_filter_apply (const struct logwatch_filter *filter, const struct logwatch_source *source, const char *line, struct error_info *err);
 
 /**
- * Handle a line from the given source by applying it to all filters
+ * Remove any filters registered with the given source
+ */
+void logwatch_filter_remove (struct logwatch *ctx, const struct logwatch_source *source);
+
+/**
+ * Handle a line from the given source by applying it to all filters.
  */
 void logwatch_on_line (struct logwatch *ctx, const struct logwatch_source *source, const char *line);
 
+/**
+ * Handle a disasterous error on a logwatch_source by notifying any irc_chan's that it is linked to via our filters.
+ */
+void logwatch_on_error (struct logwatch *ctx, const struct logwatch_source *source, const struct error_info *err);