author | Tero Marttila <terom@fixme.fi> |
Thu, 26 Mar 2009 23:15:55 +0200 | |
changeset 75 | ff6272398d2e |
parent 68 | 591a574f390e |
child 87 | f0db6ebf18b9 |
permissions | -rw-r--r-- |
17 | 1 |
#ifndef IRC_LINE_H |
2 |
#define IRC_LINE_H |
|
3 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
4 |
/** |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
5 |
* @file |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
6 |
* |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
7 |
* The low-level IRC protocol unit is a line, with prefix, command and arguments |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
8 |
*/ |
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
9 |
#include "irc_proto.h" |
17 | 10 |
#include "error.h" |
11 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
12 |
/** |
18
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
13 |
* The maximum length of a line, without terminating CRLF |
17 | 14 |
*/ |
18
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
15 |
#define IRC_LINE_MAX 510 |
17 | 16 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
17 |
/** |
17 | 18 |
* The maximum number of arguments for a single command |
19 |
*/ |
|
20 |
#define IRC_ARG_MAX 15 |
|
21 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
22 |
/** |
17 | 23 |
* Chars that are invalid inside of tokens |
24 |
*/ |
|
25 |
#define IRC_TOKEN_INVALID "\r\n\n " |
|
26 |
#define IRC_TOKEN_TRAILING_INVALID "\r\n\n" |
|
27 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
28 |
/** |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
29 |
* Low-level IRC protocol unit |
17 | 30 |
*/ |
31 |
struct irc_line { |
|
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
32 |
/** The message source as a nickmask, for those messages that have a valid prefix. May be NULL otherwise */ |
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
33 |
const struct irc_nm *source; |
17 | 34 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
35 |
/** The command, either a numeric or a primary command */ |
17 | 36 |
const char *command; |
37 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
38 |
/** The arguments, with unused ones set to NULL */ |
17 | 39 |
const char *args[IRC_ARG_MAX]; |
40 |
}; |
|
41 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
42 |
/** |
17 | 43 |
* Parse an IRC message to fill in an irc_line. This mutates the value of data (to insert NULs between tokens), and |
44 |
* stores pointers into this data into the irc_line. |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
45 |
* |
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
46 |
* If the prefix is a valid nickmask, it will be stored in the given given irc_nm, and irc_line.nm set to this. |
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
47 |
* |
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
48 |
* The irc_line will have the first N args values set to valid values, and all the rest set to NULL. |
17 | 49 |
*/ |
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
50 |
err_t irc_line_parse (struct irc_line *line, struct irc_nm *nm, char *data); |
17 | 51 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
52 |
/** |
17 | 53 |
* Formats an irc_line as a protocol line into the given buffer (which should hold at least IRC_LINE_MAX bytes). |
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
54 |
* |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
55 |
* The irc_line.args are ignored from the first NULL argument onwards. |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
56 |
* |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
57 |
* An error is returned if a token has an invalid value (e.g. a space in the command or an argument other than the last |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
58 |
* one), or if the resulting line is too long. |
17 | 59 |
*/ |
60 |
err_t irc_line_build (const struct irc_line *line, char *buf); |
|
61 |
||
68
591a574f390e
add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
62 |
/** |
591a574f390e
add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
63 |
* Iterate through the arguments in an irc_line |
591a574f390e
add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
64 |
*/ |
591a574f390e
add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
65 |
#define FOREACH_IRC_LINE_ARGS(line, arg_ptr) \ |
591a574f390e
add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
66 |
for (size_t _irc_line_arg_idx = 0; _irc_line_arg_idx < IRC_ARG_MAX && (arg_ptr = line->args[_irc_line_arg_idx]); _irc_line_arg_idx++) |
591a574f390e
add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
67 |
|
17 | 68 |
#endif /* IRC_LINE_H */ |