author | Tero Marttila <terom@fixme.fi> |
Tue, 10 Mar 2009 19:52:38 +0200 | |
changeset 34 | 763f65f9df0c |
parent 18 | dedf137b504f |
child 68 | 591a574f390e |
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 |
*/ |
17 | 9 |
#include "error.h" |
10 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
11 |
/** |
18
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
12 |
* The maximum length of a line, without terminating CRLF |
17 | 13 |
*/ |
18
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
14 |
#define IRC_LINE_MAX 510 |
17 | 15 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
16 |
/** |
17 | 17 |
* The maximum number of arguments for a single command |
18 |
*/ |
|
19 |
#define IRC_ARG_MAX 15 |
|
20 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
21 |
/** |
17 | 22 |
* Chars that are invalid inside of tokens |
23 |
*/ |
|
24 |
#define IRC_TOKEN_INVALID "\r\n\n " |
|
25 |
#define IRC_TOKEN_TRAILING_INVALID "\r\n\n" |
|
26 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
27 |
/** |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
28 |
* Low-level IRC protocol unit |
17 | 29 |
*/ |
30 |
struct irc_line { |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
31 |
/** The message source, either a server name or a nickmask */ |
17 | 32 |
const char *prefix; |
33 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
34 |
/** The command, either a numeric or a primary command */ |
17 | 35 |
const char *command; |
36 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
37 |
/** The arguments, with unused ones set to NULL */ |
17 | 38 |
const char *args[IRC_ARG_MAX]; |
39 |
}; |
|
40 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
41 |
/** |
17 | 42 |
* Parse an IRC message to fill in an irc_line. This mutates the value of data (to insert NULs between tokens), and |
43 |
* 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
|
44 |
* |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
45 |
* The irc_line will have the first N args values set to valid values, and all the rest set to NULL. |
17 | 46 |
*/ |
47 |
err_t irc_line_parse (struct irc_line *line, char *data); |
|
48 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
49 |
/** |
17 | 50 |
* 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
|
51 |
* |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
52 |
* 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
|
53 |
* |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
54 |
* 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
|
55 |
* one), or if the resulting line is too long. |
17 | 56 |
*/ |
57 |
err_t irc_line_build (const struct irc_line *line, char *buf); |
|
58 |
||
59 |
#endif /* IRC_LINE_H */ |