src/irc_cmd.h
author Tero Marttila <terom@fixme.fi>
Mon, 04 May 2009 20:55:04 +0300
branchnew-transport
changeset 168 a58ad50911fc
parent 132 f2ece471fb07
child 171 b54f393c3df0
permissions -rw-r--r--
refactor test.c into tests/*
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
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
     8
 *
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
     9
 * XXX: irc_cmd_remove called from iniside irc_cmd_invoke?
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
    10
 */
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
    11
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
#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
    13
#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
    14
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
    15
/**
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    16
 * 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
    17
 *
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    18
 * 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
    19
 */
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
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
    21
    /** 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
    22
    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
    23
87
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
     * The handler function.
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    26
     *
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    27
     * @param line the irc_line that matched the command
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    28
     * @param arg the context arg, as given to irc_cmd_add.
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    29
     */
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
    30
    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
    31
};
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
    32
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
/**
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    34
 * 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
    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
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
    37
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
    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
 * 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
    40
 */
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
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
    42
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
    43
/**
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    44
 * 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
    45
 *
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    46
 * @param handlers the irc_cmd_handlers_t
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    47
 * @param list the { NULL, NULL } termianted array of irc_cmd_handlers
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    48
 * @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
    49
 */
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
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
    51
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
    52
/**
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    53
 * Trigger all relevant handlers for the given irc_line.
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    54
 *
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    55
 * @param handlers the irc_cmd_handlers_t
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    56
 * @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
    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
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
    59
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
    60
/**
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    61
 * Remove a previously added handler list.
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    62
 *
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    63
 * @param handlers the irc_cmd_handlers_t
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    64
 * @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
    65
 * @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
    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
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
    68
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
    69
/**
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    70
 * Cleanup an irc_cmd_handlers list, releasing all memory.
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    71
 *
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    72
 * @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
    73
 */
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
    74
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
    75
22
c339c020fd33 add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    76
#endif /* IRC_CMD_H */