src/modules/logwatch.h
changeset 132 f2ece471fb07
parent 130 ffefb6d85ea6
child 133 e2d0c0c23b39
equal deleted inserted replaced
131:df949b399491 132:f2ece471fb07
    18  */
    18  */
    19 struct logwatch_source {
    19 struct logwatch_source {
    20     /** The logwatch context we are registered to */
    20     /** The logwatch context we are registered to */
    21     struct logwatch *ctx;
    21     struct logwatch *ctx;
    22 
    22 
       
    23     /** Our name */
       
    24     char *name;
       
    25 
    23     /** The input FIFO */
    26     /** The input FIFO */
    24     struct line_proto *lp;
    27     struct line_proto *lp;
    25 
    28 
    26     /** Our entry in logwatch::sources */
    29     /** Our entry in logwatch::sources */
    27     TAILQ_ENTRY(logwatch_source) logwatch_sources;
    30     TAILQ_ENTRY(logwatch_source) logwatch_sources;
    29 
    32 
    30 /**
    33 /**
    31  * Maximum length of input lines
    34  * Maximum length of input lines
    32  */
    35  */
    33 #define LOGWATCH_SOURCE_LINE_MAX 1024
    36 #define LOGWATCH_SOURCE_LINE_MAX 1024
       
    37 
       
    38 /**
       
    39  * Logwatch's per-channel state
       
    40  */
       
    41 struct logwatch_chan {
       
    42     /** The logwatch context we are registered to */
       
    43     struct logwatch *ctx;
       
    44 
       
    45     /** The actual irc_chan */
       
    46     struct irc_chan *irc_chan;
       
    47 
       
    48     /** Number of references */
       
    49     size_t refcount;
       
    50 
       
    51     /** Our entry in logwatch::channels */
       
    52     TAILQ_ENTRY(logwatch_chan) logwatch_channels;
       
    53 };
    34 
    54 
    35 /**
    55 /**
    36  * A filter specifies what lines to match, and how to then format the output.
    56  * A filter specifies what lines to match, and how to then format the output.
    37  */
    57  */
    38 struct logwatch_filter {
    58 struct logwatch_filter {
    56     char *format;
    76     char *format;
    57 
    77 
    58     /**
    78     /**
    59      * The channel to send output to 
    79      * The channel to send output to 
    60      */
    80      */
    61     struct irc_chan *chan;
    81     struct logwatch_chan *chan;
    62 
    82 
    63     /** Our entry in logwatch::filters */
    83     /** Our entry in logwatch::filters */
    64     TAILQ_ENTRY(logwatch_filter) logwatch_filters;
    84     TAILQ_ENTRY(logwatch_filter) logwatch_filters;
    65 };
    85 };
    66 
    86 
    73  * Maximum length of output string, not including NUL byte
    93  * Maximum length of output string, not including NUL byte
    74  */
    94  */
    75 #define LOGWATCH_FILTER_OUT_MAX 450
    95 #define LOGWATCH_FILTER_OUT_MAX 450
    76 
    96 
    77 /**
    97 /**
    78  * A channel for outputting logwatch output
       
    79  *
       
    80  * XXX; do we need this?
       
    81  */
       
    82 struct logwatch_chan {
       
    83     /** The channel... */
       
    84     struct irc_chan *chan;
       
    85 
       
    86     /** Our entry in logwatch::channels */
       
    87     TAILQ_ENTRY(logwatch_chan) logwatch_channels;
       
    88 };
       
    89 
       
    90 /**
       
    91  * The logwatch module state
    98  * The logwatch module state
    92  */
    99  */
    93 struct logwatch {
   100 struct logwatch {
    94     /** The nexus we are loaded on */
   101     /** The nexus we are loaded on */
    95     struct nexus *nexus;
   102     struct nexus *nexus;
    98     TAILQ_HEAD(logwatch_source_list, logwatch_source) sources;
   105     TAILQ_HEAD(logwatch_source_list, logwatch_source) sources;
    99 
   106 
   100     /** List of filters */
   107     /** List of filters */
   101     TAILQ_HEAD(logwatch_filter_list, logwatch_filter) filters;
   108     TAILQ_HEAD(logwatch_filter_list, logwatch_filter) filters;
   102 
   109 
   103     /** List of output channels */
   110     /** List of chanenls */
   104     TAILQ_HEAD(logwatch_chan_list, logwatch_chan) channels;
   111     TAILQ_HEAD(logwatch_chan_list, logwatch_chan) channels;
   105 };
   112 };
   106 
   113 
   107 /**
   114 /**
   108  * Add a new FIFO logwatch_source
   115  * Add a new FIFO logwatch_source
   109  *
   116  *
   110  * @param ctx the logwatch state
   117  * @param ctx the logwatch state
   111  * @param path the path to the fifo
   118  * @param path the path to the fifo, also used as the name
   112  * @param err returned error info
   119  * @param err returned error info
   113  * @return the new logwatch_source, or NULL on error
   120  * @return the new logwatch_source, or NULL on error
   114  */
   121  */
   115 struct logwatch_source* logwatch_open_fifo (struct logwatch *ctx, const char *path, struct error_info *err);
   122 struct logwatch_source* logwatch_open_fifo (struct logwatch *ctx, const char *path, struct error_info *err);
   116 
   123 
   117 /**
   124 /**
   118  * Destroy a source, removing it from the list of sources.
   125  * Destroy a source, removing it from the list of sources.
   119  *
   126  *
   120  * XXX: remove all affected filters as well?
   127  * XXX: remove all affected filters as well
   121  */
   128  */
   122 void logwatch_source_destroy (struct logwatch_source *source);
   129 void logwatch_source_destroy (struct logwatch_source *source);
   123 
   130 
   124 /**
   131 /**
   125  * Add a new output channel
   132  * Lookup a logwatch_source by name
       
   133  */
       
   134 const struct logwatch_source* logwatch_source_lookup (struct logwatch *ctx, const char *name);
       
   135 
       
   136 /**
       
   137  * Find an existing logwatch_chan for the given channel, or create a new one. Returns a real reference that should be
       
   138  * returned using logwatch_put_chan().
   126  *
   139  *
   127  * XXX; do we need this?
   140  * @returns NULL on ERR_CALLOC
   128  */
   141  */
   129 struct logwatch_chan* logwatch_add_chan (struct logwatch *ctx, struct irc_chan *chan, struct error_info *err);
   142 struct logwatch_chan* logwatch_get_chan (struct logwatch *ctx, struct irc_chan *irc_chan);
       
   143 
       
   144 /**
       
   145  * Returns a reference aquired using logwatch_get_chan().
       
   146  */
       
   147 void logwatch_put_chan (struct logwatch_chan *chan);
   130 
   148 
   131 /**
   149 /**
   132  * Add a new filter.
   150  * Add a new filter.
       
   151  *
       
   152  * The given logwatch_chan should be a new reference.
   133  */
   153  */
   134 struct logwatch_filter* logwatch_filter (struct logwatch *ctx, const char *name, const struct logwatch_source *source,
   154 struct logwatch_filter* logwatch_filter (struct logwatch *ctx, const char *name, const struct logwatch_source *source,
   135         const char *pattern, const char *fmt, struct irc_chan *chan, struct error_info *err);
   155         const char *pattern, const char *format, struct logwatch_chan *chan, struct error_info *err);
   136 
   156 
   137 /**
   157 /**
   138  * Destroy a logwatch_filter, unregistering it
   158  * Destroy a logwatch_filter, unregistering it
   139  */
   159  */
   140 void logwatch_filter_destroy (struct logwatch_filter *filter);
   160 void logwatch_filter_destroy (struct logwatch_filter *filter);
   143  * Pass the given line (from the given source) through the given filter
   163  * Pass the given line (from the given source) through the given filter
   144  */
   164  */
   145 err_t logwatch_filter_apply (const struct logwatch_filter *filter, const struct logwatch_source *source, const char *line, struct error_info *err);
   165 err_t logwatch_filter_apply (const struct logwatch_filter *filter, const struct logwatch_source *source, const char *line, struct error_info *err);
   146 
   166 
   147 /**
   167 /**
   148  * Handle a line from the given source by applying it to all filters
   168  * Remove any filters registered with the given source
       
   169  */
       
   170 void logwatch_filter_remove (struct logwatch *ctx, const struct logwatch_source *source);
       
   171 
       
   172 /**
       
   173  * Handle a line from the given source by applying it to all filters.
   149  */
   174  */
   150 void logwatch_on_line (struct logwatch *ctx, const struct logwatch_source *source, const char *line);
   175 void logwatch_on_line (struct logwatch *ctx, const struct logwatch_source *source, const char *line);
   151 
   176 
       
   177 /**
       
   178  * Handle a disasterous error on a logwatch_source by notifying any irc_chan's that it is linked to via our filters.
       
   179  */
       
   180 void logwatch_on_error (struct logwatch *ctx, const struct logwatch_source *source, const struct error_info *err);