src/irc_cmd.h
author Tero Marttila <terom@fixme.fi>
Sat, 11 Apr 2009 06:03:24 +0300
changeset 130 ffefb6d85ea6
parent 87 f0db6ebf18b9
child 132 f2ece471fb07
permissions -rw-r--r--
implement logwatch_filter::format using str_format
22
c339c020fd33 add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#ifndef IRC_CMD_H
c339c020fd33 add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#define IRC_CMD_H
c339c020fd33 add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
     4
/**
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
     5
 * @file
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
     6
 *
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
     7
 * Command handlers callback lists for use with irc_line's
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
     8
 */
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
     9
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    10
#include "irc_line.h"
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    11
#include "chain.h"
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    12
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    13
/**
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    14
 * A single command name + handler function lookup entry. This defines the irc_line::command to handle, and the function used to handle it.
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    15
 *
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    16
 * Note that when an irc_line is matched against an array of these, only the *first* matching handler is invoked.
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    17
 */
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    18
struct irc_cmd_handler {
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    19
    /** The command name to match */
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    20
    const char *command;
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    21
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    22
    /**
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    23
     * The handler function.
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    24
     *
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    25
     * @param line the irc_line that matched the command
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    26
     * @param arg the context arg, as given to irc_cmd_add.
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    27
     */
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    28
    void (*func) (const struct irc_line *line, void *arg);
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    29
};
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    30
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    31
/**
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    32
 * A dynamic list of irc_cmd_handler's
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    33
 */
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    34
typedef struct chain_list irc_cmd_handlers_t;
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    35
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    36
/**
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    37
 * Initialize a irc_cmd_handlers list.
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    38
 */
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    39
void irc_cmd_init (irc_cmd_handlers_t *handlers);
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    40
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    41
/**
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    42
 * Append the given NULL-termianted array of irc_cmd_handler's to the irc_cmd_handlers list, without copying it.
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    43
 *
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    44
 * @param handlers the irc_cmd_handlers_t
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    45
 * @param list the { NULL, NULL } termianted array of irc_cmd_handlers
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    46
 * @param arg the opaque context argument, will be passed to the func's of the given list when invoked
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    47
 */
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    48
err_t irc_cmd_add (irc_cmd_handlers_t *handlers, const struct irc_cmd_handler *list, void *arg);
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    49
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    50
/**
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    51
 * Trigger all relevant handlers for the given irc_line.
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    52
 *
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    53
 * @param handlers the irc_cmd_handlers_t
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    54
 * @param line the line to match against the handlers and invoke the func with
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    55
 */
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    56
void irc_cmd_invoke (irc_cmd_handlers_t *handlers, const struct irc_line *line);
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    57
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    58
/**
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    59
 * Remove a previously added handler list.
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    60
 *
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    61
 * @param handlers the irc_cmd_handlers_t
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    62
 * @param list the list given to irc_cmd_add, compared as pointer value
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    63
 * @param arg the context arg given to irc_cmd_add, compared as pointer value
69
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    64
 */
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    65
void irc_cmd_remove (irc_cmd_handlers_t *handlers, const struct irc_cmd_handler *list, void *arg);
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    66
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    67
/**
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    68
 * Cleanup an irc_cmd_handlers list, releasing all memory.
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    69
 *
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    70
 * @param handlers the irc_cmd_handlers_t to cleanup
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    71
 */
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    72
void irc_cmd_free (irc_cmd_handlers_t *handlers);
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    73
22
c339c020fd33 add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    74
#endif /* IRC_CMD_H */