author | Tero Marttila <terom@fixme.fi> |
Thu, 28 May 2009 01:17:36 +0300 | |
branch | new-lib-errors |
changeset 219 | cefec18b8268 |
parent 171 | b54f393c3df0 |
permissions | -rw-r--r-- |
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 | 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 | 16 |
* A single command name + handler function lookup entry. This defines the irc_line::command to handle, and the function used to handle it. |
17 |
* |
|
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 { |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
21 |
/** Command name to match */ |
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
|
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 | 24 |
/** |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
25 |
* Handler function. |
87 | 26 |
* |
27 |
* @param line the irc_line that matched the command |
|
28 |
* @param arg the context arg, as given to irc_cmd_add. |
|
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 |
/** |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
34 |
* A registered list of irc_cmd_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
|
35 |
*/ |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
36 |
struct irc_cmd_table { |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
37 |
CHAIN_ITEM_HEADER(irc_cmd_table); |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
38 |
|
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
39 |
/** NULL-terminated array of handlers */ |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
40 |
const struct irc_cmd_handler *list; |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
41 |
|
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
42 |
/** Context argument*/ |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
43 |
void *arg; |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
44 |
}; |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
45 |
|
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
46 |
CHAIN_HEAD_TYPE(irc_cmd_handlers, irc_cmd_table); |
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
|
47 |
|
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
|
48 |
/** |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
49 |
* Initialize a irc_cmd_handlers. |
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 |
*/ |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
51 |
void irc_cmd_init (struct irc_cmd_handlers *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
|
52 |
|
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
|
53 |
/** |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
54 |
* Append the given NULL-termianted array of irc_cmd_handler's to the irc_cmd_handlers, without copying it. |
87 | 55 |
* |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
56 |
* @param list the { NULL, NULL } termianted array of irc_cmd_handler's |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
57 |
* @param arg the context argument |
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
|
58 |
*/ |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
59 |
err_t irc_cmd_add (struct irc_cmd_handlers *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
|
60 |
|
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
|
61 |
/** |
87 | 62 |
* Trigger all relevant handlers for the given irc_line. |
63 |
* |
|
64 |
* @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
|
65 |
*/ |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
66 |
void irc_cmd_invoke (struct irc_cmd_handlers *handlers, const struct irc_line *line); |
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
|
67 |
|
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
|
68 |
/** |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
69 |
* Remove a previously added handler handlers. |
87 | 70 |
* |
71 |
* @param list the list given to irc_cmd_add, compared as pointer value |
|
72 |
* @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
|
73 |
*/ |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
74 |
void irc_cmd_remove (struct irc_cmd_handlers *handlers, const struct irc_cmd_handler list[], void *arg); |
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
|
75 |
|
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
|
76 |
/** |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
77 |
* Clears an irc_cmd_list, releasing all memory allocated by the. |
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
|
78 |
*/ |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
132
diff
changeset
|
79 |
void irc_cmd_clear (struct irc_cmd_handlers *handlers); |
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
|
80 |
|
22
c339c020fd33
add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
81 |
#endif /* IRC_CMD_H */ |