author | Tero Marttila <terom@fixme.fi> |
Wed, 27 May 2009 23:57:48 +0300 | |
branch | new-lib-errors |
changeset 217 | 7728d6ec3abf |
parent 190 | 69fd25c8484c |
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 |
/** |
90
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
13 |
* The maximum length of a line, without terminating CRLF, but including NUL |
17 | 14 |
*/ |
90
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
15 |
#define IRC_LINE_MAX (510 + 1) |
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 " |
|
87 | 26 |
|
27 |
/** |
|
28 |
* Chars that are invalid inside of the trailing-argument token |
|
29 |
*/ |
|
17 | 30 |
#define IRC_TOKEN_TRAILING_INVALID "\r\n\n" |
31 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
32 |
/** |
87 | 33 |
* Low-level IRC protocol unit. Note that all fields are specifically constant strings, MUST NOT be modified, and |
34 |
* usually point at stack-allocated memory. Hence, if you need to mutate or store these values, you must copy them. |
|
17 | 35 |
*/ |
36 |
struct irc_line { |
|
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
37 |
/** 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
|
38 |
const struct irc_nm *source; |
17 | 39 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
40 |
/** The command, either a numeric or a primary command */ |
17 | 41 |
const char *command; |
42 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
43 |
/** The arguments, with unused ones set to NULL */ |
17 | 44 |
const char *args[IRC_ARG_MAX]; |
45 |
}; |
|
46 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
47 |
/** |
87 | 48 |
* Parse an IRC message to fill in an irc_line. This mutates the contents of data (to insert NULs between tokens), and |
49 |
* stores pointers into this memory in the irc_line. |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
50 |
* |
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
51 |
* 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
|
52 |
* |
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
53 |
* The irc_line will have the first N args values set to valid values, and all the rest set to NULL. |
190
69fd25c8484c
add tests for irc_cmd/irc_line, and fix handling of missing-prefix to set source to NULL in irc_line
Tero Marttila <terom@fixme.fi>
parents:
90
diff
changeset
|
54 |
* |
69fd25c8484c
add tests for irc_cmd/irc_line, and fix handling of missing-prefix to set source to NULL in irc_line
Tero Marttila <terom@fixme.fi>
parents:
90
diff
changeset
|
55 |
* XXX: strip trailing \r\n |
17 | 56 |
*/ |
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
57 |
err_t irc_line_parse (struct irc_line *line, struct irc_nm *nm, char *data); |
17 | 58 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
59 |
/** |
17 | 60 |
* 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
|
61 |
* |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
62 |
* 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
|
63 |
* |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
64 |
* 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
|
65 |
* one), or if the resulting line is too long. |
190
69fd25c8484c
add tests for irc_cmd/irc_line, and fix handling of missing-prefix to set source to NULL in irc_line
Tero Marttila <terom@fixme.fi>
parents:
90
diff
changeset
|
66 |
* |
69fd25c8484c
add tests for irc_cmd/irc_line, and fix handling of missing-prefix to set source to NULL in irc_line
Tero Marttila <terom@fixme.fi>
parents:
90
diff
changeset
|
67 |
* XXX: append trailing \r\n |
17 | 68 |
*/ |
69 |
err_t irc_line_build (const struct irc_line *line, char *buf); |
|
70 |
||
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
|
71 |
/** |
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
|
72 |
* 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
|
73 |
*/ |
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
|
74 |
#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
|
75 |
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
|
76 |
|
17 | 77 |
#endif /* IRC_LINE_H */ |